#include <Thread.h>
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 |
Thread class.
Implements pthread thread functionality.
Thread::Thread | ( | ) |
Class constructor.
Initializes the thread class attributes.
Thread::~Thread | ( | ) | [virtual] |
Class destructor.
Destroys the thread class instance.
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.
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.
msec | Specifies the thread sleep time in milliseconds. |
bool Thread::start | ( | ) |
Start thread.
Launches the thread procedure and calls run function.
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.
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. |
bool Thread::stopRequested | ( | ) | [protected] |
Check shutdown flag.
Returns the thread procedure shutdown flag set by reportStopped() method call.
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.
void * Thread::threadRun | ( | void * | pParam | ) | [static, protected] |
Run the thread Runs the thread. Initializes the thread and sets appropriate signal actions.
pParam | Pointer to thread parameters |
pthread_t Thread::threadHandle [protected] |
Thread instance handle