rllib  1
rlthread.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  rlthread.cpp - description
3  -------------------
4  begin : Tue Jan 02 2001
5  copyright : (C) 2001 by R. Lehrig
6  email : lehrig@t-online.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This library is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as *
13  * published by the Free Software Foundation *
14  * *
15  ***************************************************************************/
16 #include "rlthread.h"
17 
18 rlThread::rlThread(int max_semaphore)
19 {
21  arg.thread = this;
22  arg.user = NULL;
24  rlwrapinit_semaphore(&semaphore, max_semaphore);
25  arg.running = 0;
26 }
27 
29 {
30  arg.running = 0;
33 }
34 
35 int rlThread::create(void *(*func)(void*), void *user)
36 {
37  arg.user = user;
38  arg.running = 1;
39  return rlwthread_create(&tid, &attr, func, &arg);
40 }
41 
43 {
45 }
46 
48 {
49  return rlwthread_mutex_lock(&mutex);
50 }
51 
53 {
55 }
56 
58 {
60 }
61 
63 {
65 }
66 
67 void rlThread::threadExit(void *status)
68 {
69  arg.running = 0;
70  rlwthread_exit(status);
71 }
72 
73 int rlThread::join(void **status)
74 {
75  return rlwthread_join(tid, status);
76 }
77 
79 {
80  arg.running = 0;
81  return rlwthread_cancel(tid);
82 }
83 
84 //------------ class rlMutex ----------------------------------------------
85 //rlMutex::rlMutex(const pthread_mutexattr_t *attr)
86 //{
87 // rlwthread_mutex_init(&mutex, attr);
88 //}
89 
90 rlMutex::rlMutex(const void *attr)
91 {
93 }
94 
96 {
98 }
99 
101 {
103 }
104 
106 {
107  return rlwthread_mutex_lock(&mutex);
108 }
109 
111 {
112  return rlwthread_mutex_unlock(&mutex);
113 }
114 
115 //------------ class rlSemaphore ------------------------------------------
116 rlSemaphore::rlSemaphore(int max_semaphore)
117 {
118  rlwrapinit_semaphore(&semaphore, max_semaphore);
119 }
120 
122 {
124 }
125 
127 {
129 }
130 
132 {
134 }
int trylock()
Definition: rlthread.cpp:42
int rlwthread_mutex_destroy(pthread_mutex_t *mptr)
Definition: rlwthread.cpp:178
int rlwthread_attr_init(pthread_attr_t *attr)
Definition: rlwthread.cpp:36
THREAD_PARAM arg
Definition: rlthread.h:112
int join(void **status)
Definition: rlthread.cpp:73
WSEMAPHORE semaphore
Definition: rlthread.h:164
int rlwthread_cancel(pthread_t tid)
Definition: rlwthread.cpp:253
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 rlwthread_exit(void *status)
Definition: rlwthread.cpp:94
int cancel()
Definition: rlthread.cpp:78
int rlwthread_mutex_lock(pthread_mutex_t *mptr)
Definition: rlwthread.cpp:193
void * user
Definition: rlthread.h:30
void threadExit(void *status)
Definition: rlthread.cpp:67
rlThread * thread
Definition: rlthread.h:29
int lock()
Definition: rlthread.cpp:105
int waitSemaphore()
Definition: rlthread.cpp:57
int unlock()
Definition: rlthread.cpp:52
virtual ~rlThread()
Definition: rlthread.cpp:28
int rlwthread_mutex_trylock(pthread_mutex_t *mptr)
Definition: rlwthread.cpp:215
int create(void *(*func)(void *), void *argument)
Definition: rlthread.cpp:35
virtual ~rlMutex()
Definition: rlthread.cpp:95
rlSemaphore(int max_semaphore=1000)
Definition: rlthread.cpp:116
int rlwthread_join(pthread_t tid, void **status)
Definition: rlwthread.cpp:113
virtual ~rlSemaphore()
Definition: rlthread.cpp:121
rlMutex(const void *attr=NULL)
Definition: rlthread.cpp:90
int unlock()
Definition: rlthread.cpp:110
int incrementSemaphore()
Definition: rlthread.cpp:62
int rlwrapincrement_semaphore(WSEMAPHORE *s)
Definition: rlwthread.cpp:310
pthread_mutex_t mutex
Definition: rlthread.h:142
rlThread(int max_semphore=1000)
Definition: rlthread.cpp:18
int rlwrapinit_semaphore(WSEMAPHORE *s, int cmax)
Definition: rlwthread.cpp:268
int incrementSemaphore()
Definition: rlthread.cpp:131
int waitSemaphore()
Definition: rlthread.cpp:126
int rlwthread_mutex_unlock(pthread_mutex_t *mptr)
Definition: rlwthread.cpp:238
pthread_t tid
Definition: rlthread.h:107
int trylock()
Definition: rlthread.cpp:100
long pthread_mutexattr_t
Definition: rlwthread.h:72
int rlwthread_create(pthread_t *tid, const pthread_attr_t *attr, void *(*func)(void *), void *arg)
Definition: rlwthread.cpp:54
int rlwrapwait_semaphore(WSEMAPHORE *s)
Definition: rlwthread.cpp:341
int rlwrapdestroy_semaphore(WSEMAPHORE *s)
Definition: rlwthread.cpp:294
int lock()
Definition: rlthread.cpp:47
WSEMAPHORE semaphore
Definition: rlthread.h:110
pthread_mutex_t mutex
Definition: rlthread.h:109
int running
Definition: rlthread.h:31