#include <mt.h>
Public Member Functions | |
void | attachToCurrent () |
Makes this object to represent currently running system thread. | |
void | detach () |
Detach this thread. | |
void | disengage () |
Dispose of this object without modifying the underlying system data. | |
bool | equal (const SysThread *th1) const |
Returns true if two threads represents the same low level threads. | |
uint64 | getID () |
Returns the current thread ID. | |
bool | isCurrentThread () |
Returns true if the thread is currently running. | |
bool | join (void *&result) |
Join this thread. | |
virtual void * | run () |
Run method. | |
bool | start () |
Launches a new instance of this thread with default parameters. | |
bool | start (const ThreadParams ¶ms) |
Launches a new instance of this thread. | |
SYSTH_DATA * | sysdata () const |
SysThread (Runnable *r=0) | |
Static Public Member Functions | |
static bool | equal (const SysThread *th1, const SysThread *th2) |
static uint64 | getCurrentID () |
Returns the thread ID of the running thread. | |
static void * | RunAThread (void *) |
Protected Member Functions | |
virtual | ~SysThread () |
Protected Attributes | |
Runnable * | m_runnable |
Can be used both to run a Runnable class instance, or to run its own virtual run method.
This class is called SysThread to distinguish it from the higher level Thread. This class just encapsulates the system threading, wheres Thread gives more multithreading programming high level support, as interrupt management and multiple object wait.
Notice that we don't have a stop() or cancel() or interrupt() method in this class. This is because all stop requests are handled at higher level, by the threads interested in VM operations (so that they can be handled i.e. by the scripts). MS-Windows doesn't provide a cancelation protocol, while POSIX cancelation system doesn't allow for handling of the cancelation event (the semantic is such that cancelation of I/O blocking operations must be honored ASAP, with at least a small control on cleanup). Both ways to do the thing (i.e. none or too much) aren't good for the code we're writing above this class, so we just drop this feature and re-implement cancelation requests at higher level, preventing - controlling blocking I/O.
virtual Falcon::SysThread::~SysThread | ( | ) | [protected, virtual] |
Falcon::SysThread::SysThread | ( | Runnable * | r = 0 |
) |
void Falcon::SysThread::attachToCurrent | ( | ) |
Makes this object to represent currently running system thread.
This must be called after the constructor and before start().
void Falcon::SysThread::detach | ( | ) |
Detach this thread.
After this call, the thread will take care of destroying itself at termination. Joining threads will receive an unjoinable exception.
Notice that if the run() return value is dynamically allocate, it will be leaked, so this method should be called only for threads not returning any value.
After this call, this instance must be considered invalid.
void Falcon::SysThread::disengage | ( | ) |
Dispose of this object without modifying the underlying system data.
static bool Falcon::SysThread::equal | ( | const SysThread * | th1, | |
const SysThread * | th2 | |||
) | [inline, static] |
References equal().
bool Falcon::SysThread::equal | ( | const SysThread * | th1 | ) | const |
static uint64 Falcon::SysThread::getCurrentID | ( | ) | [static] |
Returns the thread ID of the running thread.
On POSIX systems, it returns the value of an unique value associated with each thread; on MS-Windows systems returns the system Thread ID.
uint64 Falcon::SysThread::getID | ( | ) |
Returns the current thread ID.
On POSIX systems, it returns the value of an unique value associated with each thread; on MS-Windows systems returns the system Thread ID.
bool Falcon::SysThread::isCurrentThread | ( | ) |
Returns true if the thread is currently running.
bool Falcon::SysThread::join | ( | void *& | result | ) |
Join this thread.
Wait for this thread to terminate, and return the value returned by run(). After join has returned, this thread cannot be used anymore (it is virtually destroyed).
result | The output of the run() method of this thread. |
virtual void* Falcon::SysThread::run | ( | ) | [virtual] |
Run method.
The base class method just runs the runnable's run(). It asserts( or crashes) if the runnable has not been set in the first place.
Subclasses are free to set everything they want as the run method.
static void* Falcon::SysThread::RunAThread | ( | void * | ) | [static] |
bool Falcon::SysThread::start | ( | ) | [inline] |
bool Falcon::SysThread::start | ( | const ThreadParams & | params | ) |
Launches a new instance of this thread.
Only one start can be performed for a thread. Trying to execute start more than once will fail.
SYSTH_DATA* Falcon::SysThread::sysdata | ( | ) | const [inline] |
Runnable* Falcon::SysThread::m_runnable [protected] |