#include <rlthread.h>


Public Member Functions | |
| rlThread (int max_semphore=1000) | |
| virtual | ~rlThread () |
| int | create (void *(*func)(void *), void *argument) |
| int | trylock () |
| int | lock () |
| int | unlock () |
| int | waitSemaphore () |
| int | incrementSemaphore () |
| int | join (void **status) |
| int | cancel () |
| void | threadExit (void *status) |
Public Attributes | |
| pthread_t | tid |
| pthread_attr_t | attr |
| pthread_mutex_t | mutex |
| WSEMAPHORE | semaphore |
Private Attributes | |
| THREAD_PARAM | arg |
Thread functions based on POSIX threads.
Definition at line 38 of file rlthread.h.
| rlThread::rlThread | ( | int | max_semphore = 1000 |
) |
Definition at line 18 of file rlthread.cpp.
00019 { 00020 rlwthread_attr_init(&attr); 00021 arg.thread = this; 00022 arg.user = NULL; 00023 rlwthread_mutex_init(&mutex, NULL); 00024 rlwrapinit_semaphore(&semaphore, max_semaphore); 00025 arg.running = 0; 00026 }
| rlThread::~rlThread | ( | ) | [virtual] |
Definition at line 28 of file rlthread.cpp.
00029 { 00030 arg.running = 0; 00031 rlwthread_mutex_destroy(&mutex); 00032 rlwrapdestroy_semaphore(&semaphore); 00033 }
| int rlThread::cancel | ( | ) |
Cancel the thread
Definition at line 78 of file rlthread.cpp.
00079 { 00080 arg.running = 0; 00081 return rlwthread_cancel(tid); 00082 }
| int rlThread::create | ( | void *(*)(void *) | func, | |
| void * | argument | |||
| ) |
Create a new thread Your thread function looks like:
void *threadFunction(void *arg)
{
THREAD_PARAM *p = (THREAD_PARAM *) arg;
YOUR_DATA *d = (YOUR_DATA *) p->user; for(int i=0; i<50; i++)
{
p->thread->lock();
do something critical
printf("this is the thread\n");
p->thread->unlock();
}return NULL; }
Definition at line 35 of file rlthread.cpp.
| int rlThread::incrementSemaphore | ( | ) |
Increment the value of the semaphore
Definition at line 62 of file rlthread.cpp.
00063 { 00064 return rlwrapincrement_semaphore(&semaphore); 00065 }
| int rlThread::join | ( | void ** | status | ) |
Wait for termination of thread and get the exit status
Definition at line 73 of file rlthread.cpp.
00074 { 00075 return rlwthread_join(tid, status); 00076 }
| int rlThread::lock | ( | ) |
Lock the mutex.
Definition at line 47 of file rlthread.cpp.
00048 { 00049 return rlwthread_mutex_lock(&mutex); 00050 }
| void rlThread::threadExit | ( | void * | status | ) |
Terminate the thread and return exit status
Definition at line 67 of file rlthread.cpp.
00068 { 00069 arg.running = 0; 00070 rlwthread_exit(status); 00071 }
| int rlThread::trylock | ( | ) |
Try to lock the mutex. return 0 if already locked return !0 if lock sucessfull
Definition at line 42 of file rlthread.cpp.
00043 { 00044 return rlwthread_mutex_trylock(&mutex); 00045 }
| int rlThread::unlock | ( | ) |
Unlock the mutex.
Definition at line 52 of file rlthread.cpp.
00053 { 00054 return rlwthread_mutex_unlock(&mutex); 00055 }
| int rlThread::waitSemaphore | ( | ) |
Wait until semaphore is signaled
Definition at line 57 of file rlthread.cpp.
00058 { 00059 return rlwrapwait_semaphore(&semaphore); 00060 }
THREAD_PARAM rlThread::arg [private] |
Definition at line 112 of file rlthread.h.
| pthread_attr_t rlThread::attr |
Definition at line 108 of file rlthread.h.
| pthread_mutex_t rlThread::mutex |
Definition at line 109 of file rlthread.h.
Definition at line 110 of file rlthread.h.
| pthread_t rlThread::tid |
Definition at line 107 of file rlthread.h.
1.6.3