#include <pthread.h>
Public Member Functions | |
PThread () | |
Constructor. | |
~PThread () | |
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 | |
bool | running |
running status | |
bool | finished |
finished status |
This class stores pthread management function to use a pthread as an object
Definition at line 48 of file pthread.h.
PThread::PThread | ( | ) |
Constructor.
The class constructor. Initialize private attributes
Definition at line 37 of file pthread.cpp.
PThread::~PThread | ( | ) |
Destructor.
The class destructor
Definition at line 46 of file pthread.cpp.
References handle, and terminate().
bool PThread::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 pthread.cpp.
References threadParams::args, finished, threadParams::finished, handle, isRunning(), threadParams::process, running, threadParams::running, and threadStartup().
Referenced by RemoteControl::RemoteControl().
pthread_t * PThread::getHandle | ( | ) |
Get thread's handle.
Return pthread handle. Use this handle to use pthread functions not provided by this class
Definition at line 144 of file pthread.cpp.
References handle.
bool PThread::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 125 of file pthread.cpp.
References finished.
bool PThread::isRunning | ( | ) |
Check if the thread is running.
Give running state
Definition at line 115 of file pthread.cpp.
References running.
Referenced by exec(), and terminate().
void * PThread::join | ( | ) |
Join thread.
Wait for thread end, and then free memory
Definition at line 132 of file pthread.cpp.
References handle.
bool PThread::terminate | ( | ) |
Terminate (cancel) the thread.
Cancel the thread
Definition at line 100 of file pthread.cpp.
References handle, isRunning(), and running.
Referenced by ~PThread().
void * PThread::threadStartup | ( | void * | targs | ) | [static, private] |
threaded function
Threaded function. In this function, the thread is prepared, then the function to execute is launched.
targs | thread arguments |
Definition at line 81 of file pthread.cpp.
References threadParams::args, threadParams::finished, finished, threadParams::process, threadParams::running, and running.
Referenced by exec().
bool PThread::finished [private] |
finished status
Definition at line 56 of file pthread.h.
Referenced by exec(), isFinished(), PThread(), and threadStartup().
pthread_t* PThread::handle [private] |
pthread handle
Definition at line 52 of file pthread.h.
Referenced by exec(), getHandle(), join(), PThread(), terminate(), and ~PThread().
bool PThread::running [private] |
running status
Definition at line 54 of file pthread.h.
Referenced by exec(), isRunning(), PThread(), terminate(), and threadStartup().