#include <ArThread.h>
Inheritance diagram for ArThread:
create() will create the thread. That thread will run the given Functor.
A thread can either be in a detached state or a joinable state. If the thread is in a detached state, that thread can not be join()'ed upon. The thread will simply run until the program exits, or its function exits. A joinable thread means that another thread and call join() upon it. If this function is called, the caller will block until the thread exits its function. This gives a way to synchronize upon the lifespan of threads.
Calling cancel() will cancel the thread.
The static function self() will return a thread
Definition at line 54 of file ArThread.h.
Public Types | |
typedef std::map< ThreadType, ArThread * > | MapType |
enum | Status { STATUS_FAILED = 1, STATUS_NORESOURCE, STATUS_NO_SUCH_THREAD, STATUS_INVALID, STATUS_JOIN_SELF, STATUS_ALREADY_DETATCHED } |
typedef pthread_t | ThreadType |
Public Member Functions | |
ArThread (ArFunctor *func, bool joinable=true, bool blockAllSignals=true) | |
Constructor - starts the thread. | |
ArThread (ThreadType thread, bool joinable, bool blockAllSignals=true) | |
Constructor - starts the thread. | |
ArThread (bool blockAllSignals=true) | |
Constructor. | |
virtual void | cancel (void) |
Cancel the thread. | |
virtual int | create (ArFunctor *func, bool joinable=true, bool lowerPriority=true) |
Create and start the thread. | |
virtual int | detach (void) |
Detatch the thread so it cant be joined. | |
bool | getBlockAllSignals (void) |
Do we block all process signals at startup? | |
virtual ArFunctor * | getFunc (void) const |
Get the functor that the thread runs. | |
virtual bool | getJoinable (void) const |
Get the joinable status of the thread. | |
virtual bool | getRunning (void) const |
Get the running status of the thread. | |
virtual bool | getRunningWithLock (void) |
Get the running status of the thread, locking around the variable. | |
virtual const ThreadType * | getThread (void) const |
Get the underlying thread type. | |
virtual const char * | getThreadName (void) |
Gets the name of the functor. | |
virtual int | join (void **ret=NULL) |
Join on the thread. | |
int | lock (void) |
Lock the thread instance. | |
virtual void | logThreadInfo (void) |
Logs the information about this thread. | |
virtual void | setRunning (bool running) |
Set the running value on the thread. | |
virtual void | setThreadName (const char *name) |
Sets the name of the thread. | |
virtual void | stopRunning (void) |
Stop the thread. | |
virtual void | threadStarted (void) |
Thread to call in the function that is this thread. | |
int | tryLock (void) |
Try to lock the thread instance without blocking. | |
int | unlock (void) |
Unlock the thread instance. | |
virtual | ~ArThread () |
Destructor. | |
Static Public Member Functions | |
static void | cancelAll (void) |
Cancel all threads. | |
static ArLog::LogLevel | getLogLevel (void) |
Gets the logging level for thread information. | |
static void | init (void) |
Initialize the internal book keeping structures. | |
static void | joinAll (void) |
Join on all threads. | |
static ArThread * | self (void) |
Returns the instance of your own thread. | |
static void | setLogLevel (ArLog::LogLevel level) |
Sets the logging level for thread information. | |
static void | stopAll () |
Stop all threads. | |
static void | yieldProcessor (void) |
Yield the processor to another thread. | |
Protected Member Functions | |
virtual int | doJoin (void **ret=NULL) |
Protected Attributes | |
bool | myBlockAllSignals |
ArFunctor * | myFunc |
bool | myJoinable |
ArMutex | myMutex |
std::string | myName |
pid_t | myPID |
bool | myRunning |
State variable to denote when the thread should continue or exit. | |
ArStrMap | myStrMap |
ThreadType | myThread |
Static Protected Attributes | |
static ArLog::LogLevel | ourLogLevel = ArLog::Verbose |
static MapType | ourThreads |
static ArMutex | ourThreadsMutex |
|
Definition at line 65 of file ArThread.h. |
|
Initialize the internal book keeping structures. Initializes the internal structures which keep track of what thread is what. This is called by Aria::init(), so the user will not normaly need to call this function themselves. This funtion *must* be called from the main thread of the application. In otherwords, it should be called by main(). Definition at line 65 of file ArThread_LIN.cpp. |
|
Returns the instance of your own thread. If a newly created thread calls self() on itself too soon, this will return NULL. This is due to the fact that the thread is first created and started. Then the operating system returns the thread ID and thread that called create() then updates the list of threads with the new thread ID. There is just not much that can be done about that. The use should be aware of this caveat. Definition at line 94 of file ArThread_LIN.cpp. |
|
Thread to call in the function that is this thread. If you call this function in your functor (ie runThread) it'll then call some things for logging (to make debugging easier) Definition at line 231 of file ArThread_LIN.cpp. |