![]() |
YANE-Framework 1.1.0
|
Class to create a thread. More...
Public Member Functions | |
virtual void | detach () |
Blocks until thread is finished, no return information. | |
virtual bool | isLocked () |
Returns if thread is locked. | |
virtual bool | isRunning () |
Returns if thread is running. | |
virtual void | lock () |
Locks the thread, if already locked blocks. | |
virtual void | start () |
Creates the thread. | |
virtual void | stop () |
Stops the thread. | |
Thread (const std::string &name="Thread", DebugMaster *dm=0) | |
Constructor. | |
virtual void | trigger () |
Signal / Trigger the thread. | |
virtual bool | trylock () |
Locks the thread but returns immediately. | |
virtual void | unlock () |
Unlock the thread. | |
virtual void | wait () |
Blocks until thread is finished, possible return information. | |
virtual | ~Thread () |
Destructor. | |
Protected Member Functions | |
virtual void | debugMessage (const std::string &message, int debuglevel) |
Submit a debugmessage. | |
virtual void | debugMessageDouble (const std::string &message, const std::string &varname, int length, double *data, int debuglevel) |
Submit a debugmessage with doublevalued data. | |
virtual void | debugMessageInt (const std::string &message, const std::string &varname, int length, int *data, int debuglevel) |
Submit a debugmessage with integervalued data. | |
virtual void | debugMessageString (const std::string &message, const std::string &varname, const char *data, int debuglevel) |
Submit a debugmessage with textstring data. | |
virtual void | run ()=0 |
Function which is called after the thread is created. | |
virtual bool | waitForTrigger (unsigned int wait_msec=0, int debuglevel=0) |
Block until triggered. | |
Protected Attributes | |
bool | _abort |
DebugClient * | _debugclient |
This class is able to create a thread. To provide your own functionality overwrite the run() function. Usually you should use a loop like the following:
while(!_abort) { // do stuff }
Usually this class is used as following:
thread = new Thread(..); thread->start();
thread->stop(); thread->wait();
LIB_EXPORT yane::Utils::Thread::Thread | ( | const std::string & | name = "Thread" , |
DebugMaster * | dm = 0 |
||
) |
This creates a thread object, not the thread itself.
name | |
dm |
LIB_EXPORT void yane::Utils::Thread::debugMessage | ( | const std::string & | message, |
int | debuglevel | ||
) | [protected, virtual] |
Added for convenient handling
message | Message which is debugged |
debuglevel | Level with which the message is debugged. |
LIB_EXPORT void yane::Utils::Thread::debugMessageDouble | ( | const std::string & | message, |
const std::string & | varname, | ||
int | length, | ||
double * | data, | ||
int | debuglevel | ||
) | [protected, virtual] |
Added for convenient handling
message | Message which is debugged |
varname | Data name |
length | Length of data array |
data | Data which is added. |
debuglevel | Level with which the message is debugged. |
LIB_EXPORT void yane::Utils::Thread::debugMessageInt | ( | const std::string & | message, |
const std::string & | varname, | ||
int | length, | ||
int * | data, | ||
int | debuglevel | ||
) | [protected, virtual] |
Added for convenient handling
message | Message which is debugged |
varname | Data name |
length | Length of data array |
data | Data which is added. |
debuglevel | Level with which the message is debugged. |
LIB_EXPORT void yane::Utils::Thread::debugMessageString | ( | const std::string & | message, |
const std::string & | varname, | ||
const char * | data, | ||
int | debuglevel | ||
) | [protected, virtual] |
Added for convenient handling
message | Message which is debugged |
varname | Data name |
data | Pointer to an additional nullterminated character array, that has to be stored as data |
debuglevel | Level with which the message is debugged. |
LIB_EXPORT void yane::Utils::Thread::detach | ( | ) | [virtual] |
The calling thread is blocked until the thread is finished, no return information
LIB_EXPORT bool yane::Utils::Thread::isLocked | ( | ) | [virtual] |
Returns wether the thread is locked or not.
LIB_EXPORT bool yane::Utils::Thread::isRunning | ( | ) | [virtual] |
Returns wether the thread is running (_abort = false) or not.
LIB_EXPORT void yane::Utils::Thread::lock | ( | ) | [virtual] |
Locks the thread. If already locked the calling thread is blocked until the thread is unlocked.
virtual void yane::Utils::Thread::run | ( | ) | [protected, pure virtual] |
Overwrite this function to provide your own functionality.
Implemented in yane::NetworkedControl::CommBaseTCP, yane::NetworkedControl::ControllerThreadActuator, yane::NetworkedControl::ControllerThreadInput, yane::NetworkedControl::ControllerThreadMPC, yane::NetworkedControl::ControllerThreadOutput, and yane::NetworkedControl::ModelHandlerTCP.
LIB_EXPORT void yane::Utils::Thread::start | ( | ) | [virtual] |
This function creates the thread and should be called after creating the object.
LIB_EXPORT void yane::Utils::Thread::stop | ( | ) | [virtual] |
This function sets _abort to false, your thread should stop now.
LIB_EXPORT void yane::Utils::Thread::trigger | ( | ) | [virtual] |
Signal a thread to resume, if it's blocked due to a call to waitForTrigger()
LIB_EXPORT bool yane::Utils::Thread::trylock | ( | ) | [virtual] |
Locks the thread. If already locked returns immediately.
LIB_EXPORT void yane::Utils::Thread::unlock | ( | ) | [virtual] |
Unlocks the thread.
LIB_EXPORT void yane::Utils::Thread::wait | ( | ) | [virtual] |
The calling thread is blocked until the thread is finished, possible return information
LIB_EXPORT bool yane::Utils::Thread::waitForTrigger | ( | unsigned int | wait_msec = 0 , |
int | debuglevel = 0 |
||
) | [protected, virtual] |
The calling function (usually the thread) is blocked until the function is triggered.
wait_msec | Time until waiting is aborted. |
debuglevel | Debuglevel with which the abort message is stored. |
bool yane::Utils::Thread::_abort [protected] |
If true thread should be stopped. Value is changed by stop().
DebugClient* yane::Utils::Thread::_debugclient [protected] |
Debugclient the debug messages are stored into.