Image Component Library (ICL)
|
Simple object oriented thread class wrapping the pthread library. More...
#include <Thread.h>
Public Member Functions | |
Thread () | |
Create a new Thread. More... | |
virtual | ~Thread () |
Destructor (if the thread is still running, it is ended) More... | |
void | start () |
starts the thread More... | |
virtual void | stop () |
stops the thread and waits till it is ended More... | |
void | wait () |
waits for this thread to be ended More... | |
virtual void | run ()=0 |
pure virtual run function doing all the work More... | |
virtual void | finalize () |
at the end of the stop function, this function is called More... | |
bool | running () const |
returns the internal running state More... | |
bool | runningNoLock () const |
returns the running state of the thread (without locking the mutex) More... | |
Public Member Functions inherited from icl::utils::ShallowCopyable< ThreadImpl, ThreadImplDelOp > | |
bool | isNull () const |
returns wheter the objects implementation holds a null pointer More... | |
Static Public Member Functions | |
static void | usleep (unsigned int usec) |
just calling usleep More... | |
static void | msleep (unsigned int msecs) |
sets the current thread to sleep for some milli-seconds More... | |
static void | sleep (float secs) |
sets the current thread to sleep for some seconds More... | |
Protected Member Functions | |
void | exit () |
exits the thread using pthread_exit (must be called from within the run function) More... | |
void | lock () |
internal used lock function More... | |
int | trylock () |
internal used trylock function More... | |
void | unlock () |
internal used unlock function More... | |
void | join () |
internal used join function More... | |
Protected Member Functions inherited from icl::utils::ShallowCopyable< ThreadImpl, ThreadImplDelOp > | |
ShallowCopyable (ThreadImpl *t=0) | |
create a the implementation with a given T* value More... | |
Additional Inherited Members | |
Public Types inherited from icl::utils::ShallowCopyable< ThreadImpl, ThreadImplDelOp > | |
typedef ShallowCopyable< ThreadImpl, ThreadImplDelOp > | ParentSC |
Protected Attributes inherited from icl::utils::ShallowCopyable< ThreadImpl, ThreadImplDelOp > | |
SmartPtrBase< ThreadImpl, ThreadImplDelOp > | impl |
shared pointer for the classes implementation More... | |
Simple object oriented thread class wrapping the pthread library.
This Thread class is very simple to understand, and behaves essentially like Qts QThread. Create a custom Thread class derived from this class, reimplement the virtual run() function and use start and stop to contol the thread. a call to the threads start function will internally create a pthread which calls the Threads run() function a single time, so you have to add a while(1) statement to create a thread that is running until stop is called. Once a Thread run function returns, the corresponding pthread will call the Threads stop() function. Here is an example of a counter thread!
Additionally each Thread can be initialized with a given priority level. This feature is copied from Qt (version 4.2.x) and is not yet tested explicitly.
Although the Thread class implements the ShallowCopyable interface, it is desingned for optimal performance. On a 1.6GHz Pentium-M (linux), you can create, run, stop and release about 50.000 Threads per second. Thus it is possible to use this simple Thread implementation to create multi-threaded image processing modules as filters and so on.
TODO: Implement a dedicated class framework for this
icl::utils::Thread::Thread | ( | ) |
Create a new Thread.
|
virtual |
Destructor (if the thread is still running, it is ended)
|
protected |
exits the thread using pthread_exit (must be called from within the run function)
|
inlinevirtual |
at the end of the stop function, this function is called
|
protected |
internal used join function
|
protected |
|
static |
sets the current thread to sleep for some milli-seconds
msecs | time in msecs to sleep |
|
pure virtual |
pure virtual run function doing all the work
Implemented in icl::utils::ProcessMonitor, icl::io::dc::DCGrabberThread, icl::io::OpenNIGrabberThread, and icl::io::pylon::PylonGrabberThread.
bool icl::utils::Thread::running | ( | ) | const |
returns the internal running state
Internally, the implementation mutex will be locked here. This might cause issues
bool icl::utils::Thread::runningNoLock | ( | ) | const |
returns the running state of the thread (without locking the mutex)
this should usually be better (since less prone to producing deadlocks) then the running() method
|
static |
sets the current thread to sleep for some seconds
secs | time in secs to sleep ( float precision!) |
void icl::utils::Thread::start | ( | ) |
starts the thread
if the thread is already running, an error message is shown
|
virtual |
stops the thread and waits till it is ended
|
protected |
internal used trylock function
works like lock but without blocking (it returns immediately).
|
protected |
internal used unlock function
|
static |
just calling usleep
void icl::utils::Thread::wait | ( | ) |