ArThread Class Reference

#include <ArThread.h>

Inheritance diagram for ArThread:

ArASyncTask ArFunctorASyncTask ArRecurrentTask ArSignalHandler ArSoundsQueue List of all members.

Detailed Description

POSIX/WIN32 thread wrapper class.

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


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 ArFunctorgetFunc (void) const
 Get the functor that the thread runs.
virtual bool getJoinable (void) const
 Get the joinable status of the thread.
virtual ThreadType getOSThread (void) const
 Get the underlying os thread type.
pid_t getPID (void)
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 * getThreadActivity (void)
virtual const char * getThreadName (void)
 Gets the name of the thread.
virtual bool isThreadFinished () const
 Returns whether the thread has been completed and can be deleted.
virtual bool isThreadStarted () const
 Returns whether the thread has been started.
virtual int join (void **ret=NULL)
 Join on the thread.
int lock (void)
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 threadFinished (void)
 Marks the thread as finished and logs useful debugging information.
virtual void threadStarted (void)
 Marks the thread as started and logs useful debugging information.
int tryLock (void)
int unlock (void)
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 ThreadType getThisOSThread (void)
 Get the underlying os thread type of this thread.
static const ThreadType * getThisThread (void)
 Get the underlying thread type of this thread.
static const char * getThisThreadName (void)
 Gets the name of the this thread.
static void init (void)
 Initialize the internal book keeping structures.
static void joinAll (void)
 Join on all threads.
static ThreadType osSelf (void)
 Returns the os self of the current thread.
static ArThreadself (void)
 Returns the instance of your own thread (the current one).
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
bool myFinished
ArFunctormyFunc
bool myJoinable
ArMutex myMutex
std::string myName
pid_t myPID
bool myRunning
 State variable to denote when the thread should continue or exit.
bool myStarted
ArStrMap myStrMap
ThreadType myThread

Static Protected Attributes

static ArLog::LogLevel ourLogLevel
static MapType ourThreads
static ArMutex ourThreadsMutex
static std::string ourUnknownThreadName


Member Enumeration Documentation

enum ArThread::Status

Enumerator:
STATUS_FAILED  Failed to create the thread.
STATUS_NORESOURCE  Not enough system resources to create the thread.
STATUS_NO_SUCH_THREAD  The thread can no longer be found.
STATUS_INVALID  Thread is detached or another thread is joining on it.
STATUS_JOIN_SELF  Thread is your own thread. Can't join on self.
STATUS_ALREADY_DETATCHED  Thread is already detatched.


Member Function Documentation

virtual const char* ArThread::getThreadActivity ( void   )  [inline, virtual]

Gets a string that describes what the thread is doing NULL if it doesn't know

Reimplemented in ArASyncTask.

virtual bool ArThread::isThreadFinished (  )  const [virtual]

Returns whether the thread has been completed and can be deleted.

This is dependent on the thread implementation calling the threadFinished() method.

virtual bool ArThread::isThreadStarted (  )  const [virtual]

Returns whether the thread has been started.

This is dependent on the thread implementation calling the threadStarted() method.

int ArThread::lock ( void   )  [inline]

Lock the thread instance

Java and Python Wrappers: Not available in Java or Python wrapper libraries.

virtual void ArThread::threadFinished ( void   )  [virtual]

Marks the thread as finished and logs useful debugging information.

This method should be called after the main thread loop ends. It enables the creator of the thread to determine that the thread has actually been completed and can be deleted.

virtual void ArThread::threadStarted ( void   )  [virtual]

Marks the thread as started and logs useful debugging information.

If you call this function in your functor (ie runThread) it'll then call some things for logging (to make debugging easier) This method should be called before the main thread loop begins.

int ArThread::tryLock ( void   )  [inline]

Try to lock the thread instance without blocking

Java and Python Wrappers: Not available in Java or Python wrapper libraries.

int ArThread::unlock ( void   )  [inline]

Unlock the thread instance

Java and Python Wrappers: Not available in Java or Python wrapper libraries.


The documentation for this class was generated from the following file:
Generated on Thu Aug 6 09:39:37 2009 for Aria by  doxygen 1.5.1