#include <cppthread.h>
Public Member Functions | |
CPPThread () | |
Constructor. | |
~CPPThread () | |
Destructor. | |
bool | exec (threadProcess, void *) |
Prepare and launch a thread. | |
bool | terminate () |
Terminate (cancel) the thread. | |
bool | isRunning () |
Check if the thread is running. | |
bool | isFinished () |
Check if the thread is finished. | |
void * | join () |
Join thread. | |
pthread_t * | getHandle () |
Get thread's handle. | |
Static Private Member Functions | |
static void * | threadStartup (void *) |
threaded function | |
Private Attributes | |
pthread_t * | handle |
pthread handle | |
threadInfos | ti |
Threads informations. |
This class stores pthread management function to use a pthread as an object
Definition at line 48 of file cppthread.h.
CPPThread::CPPThread | ( | ) |
Constructor.
The class constructor. Initialize private attributes
Definition at line 37 of file cppthread.cpp.
References threadInfos::finished, handle, threadInfos::running, and ti.
CPPThread::~CPPThread | ( | ) |
Destructor.
The class destructor
Definition at line 46 of file cppthread.cpp.
References handle, and terminate().
bool CPPThread::exec | ( | threadProcess | myThreadProcess, | |
void * | args | |||
) |
Prepare and launch a thread.
Prepare and launch a thread. Stores a function to execute, and arguments, then create a thread, and launch the threadStartup
myThreadProcess | Function to execute | |
args | Arguments to send to the threaded function |
Definition at line 60 of file cppthread.cpp.
References threadInfos::args, handle, isRunning(), threadInfos::process, threadStartup(), and ti.
Referenced by BotKernel::executeFunction(), and RemoteControl::RemoteControl().
pthread_t * CPPThread::getHandle | ( | ) |
Get thread's handle.
Return pthread handle. Use this handle to use pthread functions not provided by this class
Definition at line 137 of file cppthread.cpp.
References handle.
bool CPPThread::isFinished | ( | ) |
Check if the thread is finished.
Tell if the thread is finished. The thread is concidered has finished if the exectuion has finished itself (not canceled)
Definition at line 118 of file cppthread.cpp.
References threadInfos::finished, and ti.
bool CPPThread::isRunning | ( | ) |
Check if the thread is running.
Give running state
Definition at line 108 of file cppthread.cpp.
References threadInfos::running, and ti.
Referenced by exec(), and terminate().
void * CPPThread::join | ( | ) |
Join thread.
Wait for thread end, and then free memory
Definition at line 125 of file cppthread.cpp.
References handle.
Referenced by BotKernel::executeFunction().
bool CPPThread::terminate | ( | ) |
Terminate (cancel) the thread.
Cancel the thread
Definition at line 93 of file cppthread.cpp.
References handle, isRunning(), threadInfos::running, and ti.
Referenced by BotKernel::executeFunction(), and ~CPPThread().
void * CPPThread::threadStartup | ( | void * | arg | ) | [static, private] |
threaded function
Threaded function. In this function, the thread is prepared, then the function to execute is launched.
arg | thread information structure pointer |
Definition at line 78 of file cppthread.cpp.
References threadInfos::args, threadInfos::finished, threadInfos::process, threadInfos::running, and ti.
Referenced by exec().
pthread_t* CPPThread::handle [private] |
pthread handle
Definition at line 52 of file cppthread.h.
Referenced by CPPThread(), exec(), getHandle(), join(), terminate(), and ~CPPThread().
threadInfos CPPThread::ti [private] |
Threads informations.
Definition at line 56 of file cppthread.h.
Referenced by CPPThread(), exec(), isFinished(), isRunning(), terminate(), and threadStartup().