Thread Class Reference

Thread class. More...

#include <Thread.h>

Inheritance diagram for Thread:
BarcodeReader LMXBluetoothModule NetworkConnection RfidReader GprsConnection WlanConnection

List of all members.

Public Member Functions

 Thread ()
 Class constructor.
virtual ~Thread ()
 Class destructor.
bool start ()
 Start thread.
bool stop (int timeOut=10000, bool interrupt=false)
 Stop thread.
bool terminate ()
 Terminate thread.
bool interrupt ()
 Interrupt thread execution.
void requestStop ()
 Request the stop of a thread.

Static Public Member Functions

static bool sleep (int msec)
 Sleep.

Protected Member Functions

virtual void run ()
 Thread main loop.
bool stopRequested ()
 Check shutdown flag.
void reportStopped ()
 Signal thread completion.

Static Protected Member Functions

static void * threadRun (void *pParam)
 Run the thread Runs the thread. Initializes the thread and sets appropriate signal actions.

Protected Attributes

pthread_t threadHandle

Detailed Description

Thread class.

Implements pthread thread functionality.


Constructor & Destructor Documentation

Thread::Thread (  ) 

Class constructor.

Initializes the thread class attributes.

Thread::~Thread (  )  [virtual]

Class destructor.

Destroys the thread class instance.


Member Function Documentation

bool Thread::interrupt (  ) 

Interrupt thread execution.

Sends SIGUSR1 signal to thread and causes POSIX compatible functions to abort with EINTR. Note that thread must still be terminated via the stop() call.

Returns:
Returns true if the signal was sent successfully.
void Thread::reportStopped (  )  [protected]

Signal thread completion.

Signals thread completion and indicates a successful controlled thread shutdown. Normally, the implementation does not need to call this function, as it is done automatically by the thread procedure after the run() function returns.

void Thread::requestStop (  ) 

Request the stop of a thread.

Sets a flag that the thread should stop and does not block. Call Thread::stop() afterwards to clean up after the thread to avoid memory leak!

void Thread::run (  )  [protected, virtual]

Thread main loop.

Override this to implement your worker thread. Run function gets called by the thread procedure. The thread is terminated after the run function returns.

Reimplemented in BarcodeReader, NetworkConnection, and RfidReader.

bool Thread::sleep ( int  msec  )  [static]

Sleep.

Suspends the thread for a given amount of time. You may call this static function from any location of your application code.

Parameters:
msec Specifies the thread sleep time in milliseconds.
Returns:
Returns true if the call was a success. Returns false if the thread sleep was interrupted.
bool Thread::start (  ) 

Start thread.

Launches the thread procedure and calls run function.

Returns:
Returns true if the call is successful.
bool Thread::stop ( int  timeOut = 10000,
bool  interrupt = false 
)

Stop thread.

Terminates the running thread in a controlled fashion. First, the thread termination request flag is raised. Thread implementation must then detect this condition and clean up returning from run() function.

If the thread does not react to the termination request, it is terminated in an uncontrolled way via pthread_cancel() call.

Parameters:
timeOut Specifies the amount of time to wait for a controlled thread shutdown in milliseconds.
interrupt If true, a SIGUSR1 will be sent to the thread to notify that it should be shut down.
Returns:
Returns true if the thread is stopped or terminated.
bool Thread::stopRequested (  )  [protected]

Check shutdown flag.

Returns the thread procedure shutdown flag set by reportStopped() method call.

Returns:
Returns true if the thread shutdown flag is set.
bool Thread::terminate (  ) 

Terminate thread.

Kills the thread in an uncontrolled fashion. Thread resources may not be properly released, since the thread procedure is aborted at any cancellation point, which may be arbitrary libc I/O function call.

Returns:
Returns true if the thread was terminated successfully.
void * Thread::threadRun ( void *  pParam  )  [static, protected]

Run the thread Runs the thread. Initializes the thread and sets appropriate signal actions.

Parameters:
pParam Pointer to thread parameters

Member Data Documentation

pthread_t Thread::threadHandle [protected]

Thread instance handle


The documentation for this class was generated from the following files:
Generated on Wed Oct 20 11:13:45 2010 for libspatha by  doxygen 1.6.3