2011-12-22 16:19:25 +01:00
|
|
|
/*
|
|
|
|
* \brief Pistachio thread facility
|
|
|
|
* \author Christian Helmuth
|
|
|
|
* \date 2006-04-11
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2012-01-03 15:35:05 +01:00
|
|
|
* Copyright (C) 2006-2012 Genode Labs GmbH
|
2011-12-22 16:19:25 +01:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
|
|
|
* under the terms of the GNU General Public License version 2.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _CORE__INCLUDE__PLATFORM_THREAD_H_
|
|
|
|
#define _CORE__INCLUDE__PLATFORM_THREAD_H_
|
|
|
|
|
|
|
|
/* Genode includes */
|
|
|
|
#include <base/native_types.h>
|
|
|
|
#include <base/pager.h>
|
|
|
|
#include <base/thread_state.h>
|
|
|
|
|
|
|
|
/* core includes */
|
|
|
|
#include <platform_pd.h>
|
|
|
|
|
|
|
|
/* Pistachio includes */
|
|
|
|
namespace Pistachio {
|
|
|
|
#include <l4/types.h>
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace Genode {
|
|
|
|
|
|
|
|
class Platform_pd;
|
|
|
|
class Platform_thread
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
int _thread_id; /* plain thread number */
|
|
|
|
Native_thread_id _l4_thread_id; /* L4 thread ID */
|
|
|
|
char _name[32]; /* thread name that will be
|
|
|
|
registered at the kernel
|
|
|
|
debugger */
|
|
|
|
Platform_pd *_platform_pd; /* protection domain thread
|
|
|
|
is bound to */
|
|
|
|
unsigned _priority; /* thread priority */
|
|
|
|
Pager_object *_pager;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
enum { THREAD_INVALID = -1 }; /* invalid thread number */
|
|
|
|
enum { DEFAULT_PRIORITY = 128 };
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
|
|
|
Platform_thread(const char *name = 0, unsigned priority = 0,
|
2012-05-28 16:57:09 +02:00
|
|
|
addr_t utcb = 0, int thread_id = THREAD_INVALID);
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor
|
|
|
|
*/
|
|
|
|
~Platform_thread();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Start thread
|
|
|
|
*
|
|
|
|
* \param ip instruction pointer to start at
|
|
|
|
* \param sp stack pointer to use
|
|
|
|
* \param cpu_no target cpu
|
|
|
|
*
|
|
|
|
* \retval 0 successful
|
|
|
|
* \retval -1 thread could not be started
|
|
|
|
*/
|
|
|
|
int start(void *ip, void *sp, unsigned int cpu_no = 0);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pause this thread
|
|
|
|
*/
|
|
|
|
void pause();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resume this thread
|
|
|
|
*/
|
|
|
|
void resume();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cancel currently blocking operation
|
|
|
|
*/
|
|
|
|
void cancel_blocking();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This thread is about to be bound
|
|
|
|
*
|
|
|
|
* \param thread_id local thread ID
|
|
|
|
* \param l4_thread_id final L4 thread ID
|
|
|
|
* \param pd platform pd, thread is bound to
|
|
|
|
*/
|
|
|
|
void bind(int thread_id, Native_thread_id l4_thread_id,
|
|
|
|
Platform_pd *pd);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unbind this thread
|
|
|
|
*/
|
|
|
|
void unbind();
|
|
|
|
|
|
|
|
/**
|
2012-11-12 17:48:18 +01:00
|
|
|
* Override thread state with 's'
|
2011-12-22 16:19:25 +01:00
|
|
|
*
|
2012-11-12 17:48:18 +01:00
|
|
|
* \throw Cpu_session::State_access_failed
|
|
|
|
*/
|
|
|
|
void state(Thread_state s);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read thread state
|
2011-12-22 16:19:25 +01:00
|
|
|
*/
|
2012-11-12 17:48:18 +01:00
|
|
|
Thread_state state();
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
/************************
|
|
|
|
** Accessor functions **
|
|
|
|
************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return/set pager
|
|
|
|
*/
|
|
|
|
Pager_object *pager() const { return _pager; }
|
|
|
|
void pager(Pager_object *pager) { _pager = pager; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return identification of thread when faulting
|
|
|
|
*/
|
|
|
|
unsigned long pager_object_badge() const {
|
|
|
|
return convert_native_thread_id_to_badge(_l4_thread_id); }
|
|
|
|
|
|
|
|
/**
|
2012-09-04 17:32:55 +02:00
|
|
|
* Set the executing CPU for this thread
|
2011-12-22 16:19:25 +01:00
|
|
|
*/
|
2012-09-04 17:32:55 +02:00
|
|
|
void affinity(unsigned cpu);
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**********************************
|
|
|
|
** Pistachio-specific Accessors **
|
|
|
|
**********************************/
|
|
|
|
|
|
|
|
int thread_id() const { return _thread_id; }
|
|
|
|
Native_thread_id native_thread_id() const { return _l4_thread_id; }
|
|
|
|
const char *name() const { return _name; }
|
|
|
|
|
|
|
|
/* use only for core... */
|
|
|
|
void set_l4_thread_id(Native_thread_id id) { _l4_thread_id = id; }
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* _CORE__INCLUDE__PLATFORM_THREAD_H_ */
|