rllib  1
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
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 ( int  max_semphore = 1000)

Definition at line 18 of file rlthread.cpp.

rlThread::~rlThread ( )
virtual

Member Function Documentation

int rlThread::cancel ( )
 Cancel the thread
 

Definition at line 78 of file rlthread.cpp.

{
arg.running = 0;
}
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.

{
arg.user = user;
arg.running = 1;
return rlwthread_create(&tid, &attr, func, &arg);
}
int rlThread::incrementSemaphore ( )
 Increment the value of the semaphore
 

Definition at line 62 of file rlthread.cpp.

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.

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.

int rlThread::unlock ( )
 Unlock the mutex.
 

Definition at line 52 of file rlthread.cpp.

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

Definition at line 57 of file rlthread.cpp.

Member Data Documentation

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.

WSEMAPHORE rlThread::semaphore

Definition at line 110 of file rlthread.h.

pthread_t rlThread::tid

Definition at line 107 of file rlthread.h.


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