AP_Thread Class Reference

#include <AP_Thread.h>

Inherited by AMICO_Layer, AMICO_Link, AMICO_Receiver, AMICO_link, AMICO_link_accept, AP_ActiveObject, AP_Debugger, AP_Logger, AP_MemoryPool, CarLinO_core, CarLinO_leash, CarLinO_process, GOAL_Manager, my_application, OrientationChaser, and TimeSensor.


Public Member Functions

 AP_Thread (AP_Uint32 stacksize=AP_MEDIUM_STACK)
AP_Bool isRunning (void) const
void kill (void)
virtual void run (void)
void sleepme (AP_Sint32 timeout)
 Sleep the thread. It hangs the thread on a posix semaphore.
bool spawn (const AP_Byte *name="", const AP_Byte *description="")
void stop (void)
void wait (void)
void wakeup (void)
 Wakeup the thread. It wakeup the thread that is waiting on a posix semaphore.
virtual ~AP_Thread ()

Static Public Member Functions

static void * wrapper (void *object)

Protected Attributes

AP_Byte _m_description [AP_TEXT_SIZE]
AP_Bool _m_running
AP_ThreadObject _m_thread
AP_ThreadObjectAttr _m_threadAttr
AP_Byte _m_threadName [AP_NAME_SIZE]
AP_Bool _m_wakeup


Detailed Description

The class provide an incapsulation for linux threads. You can derive from its your proprietary class that use threads. AP_Thread include a posix semaphore to provide sleep/wakeup thread meccanism.
Parameters:
_thread thread handle of type pthread_t
_mutex mutex posix for thread sections critical
_sleep posix semaphore for sleep/wakeup thread function
_running flag for thread running state (true = running, false = stopped)
_locked flag for thread section critical notify (true = inside critical section, false = out of critical section)

Constructor & Destructor Documentation

AP_Thread ( AP_Uint32  stacksize = AP_MEDIUM_STACK  ) 

Costructor of class.It create a AP_Thread object but doesn't spawn it.

~AP_Thread ( void   )  [virtual]

Distructor of class. It notifies the stop to run method and kill the thread. The distructor waits for the thread termination before exit.


Member Function Documentation

AP_Bool isRunning ( void   )  const [inline]

Status of the thread. It return the running status of thread. Used in the main loop (run) of the thread.

Returns:
true if the thread is running, flase otherwise.

void kill ( void   ) 

Kill thread function. It notifies the stop to main function (run), kill the thread and wait for thread termination.

virtual void run ( void   )  [inline, virtual]

Main thread function. It must be overloaded in your derived class. It has no parameter.

Example:
void run(void)
{
while(is_running())
{
... do something ...
}
}

Reimplemented in AMICO_link_accept, AMICO_link, AP_ActiveObject, AP_Logger, AP_MemoryPool, CarLinO_core, CarLinO_leash, CarLinO_process, GOAL_Manager, my_application, OrientationChaser, TimeSensor, AMICO_Layer, AMICO_MemoryLink, AMICO_Receiver, and AMICO_SocketLink.

void sleepme ( AP_Sint32  timeout  ) 

Sleep the thread. It hangs the thread on a posix semaphore.

bool spawn ( const AP_Byte name = "",
const AP_Byte description = "" 
)

Spawn thread function. It creates the thread and launches it.

void stop ( void   ) 

void wait ( void   ) 

void wakeup ( void   ) 

Wakeup the thread. It wakeup the thread that is waiting on a posix semaphore.

void * wrapper ( void *  object  )  [static]

Wrapper for thread creation. The static wrapper method is used to pass the main thread function (run) to linux pthread_create function. It is the tipically way to do this in C++ code.

Parameters:
object Pointer to istance of object of type AP_Thread to call the specific thread run function.

Reimplemented in class1, class2, and class3.


Field Documentation

AP_Byte _m_description[AP_TEXT_SIZE] [protected]

AP_Bool _m_running [protected]

AP_Byte _m_threadName[AP_NAME_SIZE] [protected]

AP_Bool _m_wakeup [protected]


The documentation for this class was generated from the following files:

Generated on Fri Mar 5 16:50:45 2010 for CarLinO by  doxygen 1.5.8