rllib  1
Public Member Functions | Public Attributes | Private Attributes | List of all members
rlThread Class Reference

#include <rlthread.h>

Inheritance diagram for rlThread:
Inheritance graph
[legend]
Collaboration diagram for rlThread:
Collaboration graph
[legend]

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
 

Detailed Description

Thread functions based on POSIX threads.

Definition at line 38 of file rlthread.h.

Constructor & Destructor Documentation

◆ rlThread()

rlThread::rlThread ( int  max_semphore = 1000)

Definition at line 18 of file rlthread.cpp.

19 {
21  arg.thread = this;
22  arg.user = NULL;
24  rlwrapinit_semaphore(&semaphore, max_semaphore);
25  arg.running = 0;
26 }
int rlwthread_attr_init(pthread_attr_t *attr)
Definition: rlwthread.cpp:36
THREAD_PARAM arg
Definition: rlthread.h:112
int rlwthread_mutex_init(pthread_mutex_t *mptr, const pthread_mutexattr_t *attr)
Definition: rlwthread.cpp:160
pthread_attr_t attr
Definition: rlthread.h:108
void * user
Definition: rlthread.h:30
rlThread * thread
Definition: rlthread.h:29
int rlwrapinit_semaphore(WSEMAPHORE *s, int cmax)
Definition: rlwthread.cpp:268
WSEMAPHORE semaphore
Definition: rlthread.h:110
pthread_mutex_t mutex
Definition: rlthread.h:109
int running
Definition: rlthread.h:31

◆ ~rlThread()

rlThread::~rlThread ( )
virtual

Definition at line 28 of file rlthread.cpp.

29 {
30  arg.running = 0;
33 }
int rlwthread_mutex_destroy(pthread_mutex_t *mptr)
Definition: rlwthread.cpp:178
THREAD_PARAM arg
Definition: rlthread.h:112
int rlwrapdestroy_semaphore(WSEMAPHORE *s)
Definition: rlwthread.cpp:294
WSEMAPHORE semaphore
Definition: rlthread.h:110
pthread_mutex_t mutex
Definition: rlthread.h:109
int running
Definition: rlthread.h:31

Member Function Documentation

◆ cancel()

int rlThread::cancel ( )
Cancel the thread

Definition at line 78 of file rlthread.cpp.

79 {
80  arg.running = 0;
81  return rlwthread_cancel(tid);
82 }
THREAD_PARAM arg
Definition: rlthread.h:112
int rlwthread_cancel(pthread_t tid)
Definition: rlwthread.cpp:253
pthread_t tid
Definition: rlthread.h:107
int running
Definition: rlthread.h:31

◆ create()

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.

36 {
37  arg.user = user;
38  arg.running = 1;
39  return rlwthread_create(&tid, &attr, func, &arg);
40 }
THREAD_PARAM arg
Definition: rlthread.h:112
pthread_attr_t attr
Definition: rlthread.h:108
void * user
Definition: rlthread.h:30
pthread_t tid
Definition: rlthread.h:107
int rlwthread_create(pthread_t *tid, const pthread_attr_t *attr, void *(*func)(void *), void *arg)
Definition: rlwthread.cpp:54
int running
Definition: rlthread.h:31

◆ incrementSemaphore()

int rlThread::incrementSemaphore ( )
Increment the value of the semaphore

Definition at line 62 of file rlthread.cpp.

63 {
65 }
int rlwrapincrement_semaphore(WSEMAPHORE *s)
Definition: rlwthread.cpp:310
WSEMAPHORE semaphore
Definition: rlthread.h:110

◆ join()

int rlThread::join ( void **  status)
Wait for termination of thread and get the exit status

Definition at line 73 of file rlthread.cpp.

74 {
75  return rlwthread_join(tid, status);
76 }
int rlwthread_join(pthread_t tid, void **status)
Definition: rlwthread.cpp:113
pthread_t tid
Definition: rlthread.h:107

◆ lock()

int rlThread::lock ( )
Lock the mutex.

Definition at line 47 of file rlthread.cpp.

48 {
49  return rlwthread_mutex_lock(&mutex);
50 }
int rlwthread_mutex_lock(pthread_mutex_t *mptr)
Definition: rlwthread.cpp:193
pthread_mutex_t mutex
Definition: rlthread.h:109

◆ threadExit()

void rlThread::threadExit ( void *  status)
Terminate the thread and return exit status

Definition at line 67 of file rlthread.cpp.

68 {
69  arg.running = 0;
70  rlwthread_exit(status);
71 }
THREAD_PARAM arg
Definition: rlthread.h:112
void rlwthread_exit(void *status)
Definition: rlwthread.cpp:94
int running
Definition: rlthread.h:31

◆ trylock()

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.

43 {
45 }
int rlwthread_mutex_trylock(pthread_mutex_t *mptr)
Definition: rlwthread.cpp:215
pthread_mutex_t mutex
Definition: rlthread.h:109

◆ unlock()

int rlThread::unlock ( )
Unlock the mutex.

Definition at line 52 of file rlthread.cpp.

53 {
55 }
int rlwthread_mutex_unlock(pthread_mutex_t *mptr)
Definition: rlwthread.cpp:238
pthread_mutex_t mutex
Definition: rlthread.h:109

◆ waitSemaphore()

int rlThread::waitSemaphore ( )
Wait until semaphore is signaled

Definition at line 57 of file rlthread.cpp.

58 {
60 }
int rlwrapwait_semaphore(WSEMAPHORE *s)
Definition: rlwthread.cpp:341
WSEMAPHORE semaphore
Definition: rlthread.h:110

Member Data Documentation

◆ arg

THREAD_PARAM rlThread::arg
private

Definition at line 112 of file rlthread.h.

◆ attr

pthread_attr_t rlThread::attr

Definition at line 108 of file rlthread.h.

◆ mutex

pthread_mutex_t rlThread::mutex

Definition at line 109 of file rlthread.h.

◆ semaphore

WSEMAPHORE rlThread::semaphore

Definition at line 110 of file rlthread.h.

◆ tid

pthread_t rlThread::tid

Definition at line 107 of file rlthread.h.


The documentation for this class was generated from the following files: