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();
315 {semVal = semval; semWait = 0;}
333 {
if (errno == EAGAIN)
return 0;
334 if (errno != EINTR) {
throw "sem_CondWait() failed";}
340 {
throw "sem_post() failed";}
345 {
throw "sem_wait() failed";}
351 {
throw "sem_init() failed";}
354 {
throw "sem_destroy() failed";}
377 #define XRDSYSTHREAD_BIND 0x001
382 #define XRDSYSTHREAD_HOLD 0x002
388 static int Cancel(pthread_t tid) {
return pthread_cancel(tid);}
390 static int Detach(pthread_t tid) {
return pthread_detach(tid);}
394 return pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, 0);
397 static int Join(pthread_t tid,
void **ret) {
398 return pthread_join(tid, ret);
402 return pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, 0);
406 return pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, 0);
410 return pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, 0);
414 pthread_testcancel();
418 static pthread_t
ID(
void) {
return pthread_self();}
420 static int Kill(pthread_t tid) {
return pthread_cancel(tid);}
422 static unsigned long Num(
void);
424 static int Run(pthread_t *,
void *(*proc)(
void *),
void *arg,
425 int opts=0,
const char *desc = 0);
427 static int Same(pthread_t t1, pthread_t t2)
428 {
return pthread_equal(t1, t2);}
434 static int Signal(pthread_t tid,
int snum)
435 {
return pthread_kill(tid, snum);}
437 static int Wait(pthread_t tid);