39 #include "XrdSys/XrdWin32.hh"
41 #include <sys/types.h>
42 #if defined(__linux__)
43 #include <sys/syscall.h>
56 void *(*proc)(
void *);
60 void *(*p)(
void *),
void *a)
71 size_t XrdSysThread::stackSize = 0;
105 if (relMutex)
Lock();
106 retc = pthread_cond_wait(&cvar, &cmut);
123 struct timespec tval;
127 if (msec < 1000) sec = 0;
128 else {sec = msec / 1000; msec = msec % 1000;}
133 if (relMutex)
Lock();
137 gettimeofday(&tnow, 0);
141 tval.tv_sec = tnow.tv_sec + sec;
142 tval.tv_nsec = tnow.tv_usec + usec;
143 if (tval.tv_nsec >= 1000000)
144 {tval.tv_sec += tval.tv_nsec / 1000000;
145 tval.tv_nsec = tval.tv_nsec % 1000000;
147 tval.tv_nsec *= 1000;
152 do {retc = pthread_cond_timedwait(&cvar, &cmut, &tval);}
153 while (retc && (retc == EINTR));
159 if (retc && retc != ETIMEDOUT) {
throw "cond_timedwait() failed";}
160 return retc == ETIMEDOUT;
174 struct timespec tval;
178 if (msec < 1000) sec = 0;
179 else {sec = msec / 1000; msec = msec % 1000;}
184 gettimeofday(&tnow, 0);
188 tval.tv_sec = tnow.tv_sec + sec;
189 tval.tv_nsec = tnow.tv_usec + usec;
190 if (tval.tv_nsec >= 1000000)
191 {tval.tv_sec += tval.tv_nsec / 1000000;
192 tval.tv_nsec = tval.tv_nsec % 1000000;
194 tval.tv_nsec *= 1000;
199 do {retc = pthread_cond_timedwait(&
cvar,
mtxP, &tval);}
200 while (retc && (retc == EINTR));
204 if (retc && retc != ETIMEDOUT) {
throw "cond_timedwait() failed";}
205 return retc == ETIMEDOUT;
215 #if defined(__APPLE__) || defined(__GNU__)
224 if ((rc = (semVal > 0) && !semWait)) semVal--;
240 if (semVal && semWait) semVar.Signal();
258 pthread_cleanup_push(&XrdSysSemaphore::CleanUp, (
void *) &semVar);
259 if (semVal < 1 || semWait)
269 pthread_cleanup_pop(1);
276 void XrdSysSemaphore::CleanUp(
void *semVar)
292 #if defined(__linux__)
293 return static_cast<unsigned long>(syscall(SYS_gettid));
294 #elif defined(__solaris__)
295 return static_cast<unsigned long>(pthread_self());
296 #elif defined(__APPLE__)
297 return static_cast<unsigned long>(pthread_mach_thread_np(pthread_self()));
299 return static_cast<unsigned long>(getpid());
308 int opts,
const char *tDesc)
310 pthread_attr_t tattr;
315 pthread_attr_init(&tattr);
317 pthread_attr_setscope(&tattr, PTHREAD_SCOPE_SYSTEM);
319 pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
321 pthread_attr_setstacksize(&tattr, stackSize);
323 static_cast<void *
>(myargs));
336 {pthread_attr_t tattr;
338 pthread_attr_init(&tattr);
339 if (pthread_attr_getstacksize(&tattr, &dflt_stk_sz) || stksz <= dflt_stk_sz)
357 if ((retc = pthread_join(tid,
reinterpret_cast<void **
>(&tstat))))
return retc;
374 pthread_mutexattr_t attr;
376 rc = pthread_mutexattr_init( &attr );
380 pthread_mutexattr_settype( &attr, PTHREAD_MUTEX_RECURSIVE );
381 pthread_mutex_destroy( &
cs );
382 rc = pthread_mutex_init( &
cs, &attr );
385 pthread_mutexattr_destroy(&attr);
391 pthread_mutex_destroy( &
cs );
static XrdSysError eDest(0,"crypto_")
void * XrdSysThread_Xeq(void *myargs)
#define XRDSYSTHREAD_BIND
#define XRDSYSTHREAD_HOLD
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
static int Wait(pthread_t tid)
static int Run(pthread_t *, void *(*proc)(void *), void *arg, int opts=0, const char *desc=0)
static void setStackSize(size_t stsz, bool force=false)
static unsigned long Num(void)
XrdSysThreadArgs(XrdSysError *ed, const char *td, void *(*p)(void *), void *a)