1 #ifndef __SYS_PTHREAD__
2 #define __SYS_PTHREAD__
34 #define HAVE_STRUCT_TIMESPEC 1
41 #include <semaphore.h>
57 inline void Lock() {pthread_mutex_lock(&
cmut);}
60 pthread_cond_signal(&
cvar);
65 pthread_cond_broadcast(&
cvar);
77 ) {pthread_cond_init(&
cvar, NULL);
78 pthread_mutex_init(&
cmut, NULL);
82 pthread_mutex_destroy(&
cmut);
119 {
if (CndVar) CndVar->Lock();
145 {
if (pthread_mutex_trylock( &
cs ))
return 0;
149 inline void Lock() {pthread_mutex_lock(&
cs);}
204 {
if (mutex) mutex->Lock();
229 {
if (pthread_rwlock_tryrdlock( &
lock ))
return 0;
233 {
if (pthread_rwlock_trywrlock( &
lock ))
return 0;
247 pthread_rwlock_destroy(&
lock);
248 pthread_rwlock_init(&
lock, NULL);
278 {
if (l) {
if (rd) l->ReadLock();
314 static void CleanUp(
void *semVar);
317 {semVal = semval; semWait = 0;}
335 {
if (errno == EAGAIN)
return 0;
336 if (errno != EINTR) {
throw "sem_CondWait() failed";}
342 {
throw "sem_post() failed";}
347 {
throw "sem_wait() failed";}
353 {
throw "sem_init() failed";}
356 {
throw "sem_destroy() failed";}
379 #define XRDSYSTHREAD_BIND 0x001
384 #define XRDSYSTHREAD_HOLD 0x002
390 static int Cancel(pthread_t tid) {
return pthread_cancel(tid);}
392 static int Detach(pthread_t tid) {
return pthread_detach(tid);}
396 return pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, 0);
399 static int Join(pthread_t tid,
void **ret) {
400 return pthread_join(tid, ret);
404 return pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, 0);
408 return pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, 0);
412 return pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, 0);
416 pthread_testcancel();
420 static pthread_t
ID(
void) {
return pthread_self();}
422 static int Kill(pthread_t tid) {
return pthread_cancel(tid);}
424 static unsigned long Num(
void);
426 static int Run(pthread_t *,
void *(*proc)(
void *),
void *arg,
427 int opts=0,
const char *desc = 0);
429 static int Same(pthread_t t1, pthread_t t2)
430 {
return pthread_equal(t1, t2);}
436 static int Signal(pthread_t tid,
int snum)
437 {
return pthread_kill(tid, snum);}
439 static int Wait(pthread_t tid);