|
rllib
1
|
#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.
{
rlwthread_attr_init(&attr);
arg.thread = this;
arg.user = NULL;
rlwthread_mutex_init(&mutex, NULL);
rlwrapinit_semaphore(&semaphore, max_semaphore);
arg.running = 0;
}
| rlThread::~rlThread | ( | ) | [virtual] |
Definition at line 28 of file rlthread.cpp.
{
arg.running = 0;
rlwthread_mutex_destroy(&mutex);
rlwrapdestroy_semaphore(&semaphore);
}
| int rlThread::cancel | ( | ) |
Cancel the thread
Definition at line 78 of file rlthread.cpp.
{
arg.running = 0;
return rlwthread_cancel(tid);
}
| 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.
{
return rlwrapincrement_semaphore(&semaphore);
}
| int rlThread::join | ( | void ** | status | ) |
Wait for termination of thread and get the exit status
Definition at line 73 of file rlthread.cpp.
{
return rlwthread_join(tid, status);
}
| int rlThread::lock | ( | ) |
Lock the mutex.
Definition at line 47 of file rlthread.cpp.
{
return rlwthread_mutex_lock(&mutex);
}
| void rlThread::threadExit | ( | void * | status | ) |
Terminate the thread and return exit status
Definition at line 67 of file rlthread.cpp.
{
arg.running = 0;
rlwthread_exit(status);
}
| 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.
{
return rlwthread_mutex_trylock(&mutex);
}
| int rlThread::unlock | ( | ) |
Unlock the mutex.
Definition at line 52 of file rlthread.cpp.
{
return rlwthread_mutex_unlock(&mutex);
}
| int rlThread::waitSemaphore | ( | ) |
Wait until semaphore is signaled
Definition at line 57 of file rlthread.cpp.
{
return rlwrapwait_semaphore(&semaphore);
}
THREAD_PARAM rlThread::arg [private] |
Definition at line 112 of file rlthread.h.
Definition at line 108 of file rlthread.h.
Definition at line 109 of file rlthread.h.
Definition at line 110 of file rlthread.h.
Definition at line 107 of file rlthread.h.
1.7.5.1