1 #ifndef __SYS_PTHREAD__
2 #define __SYS_PTHREAD__
15 #define HAVE_STRUCT_TIMESPEC 1
22 #include <semaphore.h>
38 inline void Lock() {pthread_mutex_lock(&
cmut);}
41 pthread_cond_signal(&
cvar);
46 pthread_cond_broadcast(&
cvar);
58 ) {pthread_cond_init(&
cvar, NULL);
59 pthread_mutex_init(&
cmut, NULL);
63 pthread_mutex_destroy(&
cmut);
100 {
if (CndVar) CndVar->Lock();
126 {
if (pthread_mutex_trylock( &
cs ))
return 0;
130 inline void Lock() {pthread_mutex_lock(&
cs);}
185 {
if (mutex) mutex->Lock();
210 {
if (pthread_rwlock_tryrdlock( &
lock ))
return 0;
214 {
if (pthread_rwlock_trywrlock( &
lock ))
return 0;
253 {
if (l) {
if (rd) l->ReadLock();
290 {semVal = semval; semWait = 0;}
308 {
if (errno == EAGAIN)
return 0;
309 if (errno != EINTR) {
throw "sem_CondWait() failed";}
315 {
throw "sem_post() failed";}
320 {
throw "sem_wait() failed";}
326 {
throw "sem_init() failed";}
329 {
throw "sem_destroy() failed";}
352 #define XRDSYSTHREAD_BIND 0x001
357 #define XRDSYSTHREAD_HOLD 0x002
363 static int Cancel(pthread_t tid) {
return pthread_cancel(tid);}
365 static int Detach(pthread_t tid) {
return pthread_detach(tid);}
369 return pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, 0);
372 static int Join(pthread_t tid,
void **ret) {
373 return pthread_join(tid, ret);
377 return pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, 0);
381 return pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, 0);
385 return pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, 0);
389 pthread_testcancel();
393 static pthread_t
ID(
void) {
return pthread_self();}
395 static int Kill(pthread_t tid) {
return pthread_cancel(tid);}
397 static unsigned long Num(
void);
399 static int Run(pthread_t *,
void *(*proc)(
void *),
void *arg,
400 int opts=0,
const char *desc = 0);
402 static int Same(pthread_t t1, pthread_t t2)
403 {
return pthread_equal(t1, t2);}
409 static int Signal(pthread_t tid,
int snum)
410 {
return pthread_kill(tid, snum);}
412 static int Wait(pthread_t tid);