32 #define SEM_VALUE_MAX ((int) ((~0u) >> 1)) 64 S = CreateSemaphore(0,initValue,SEM_VALUE_MAX,0);
77 pthread_cond_destroy(&
_cond);
91 bool acquire(
int n = 1,
int ms = 0)
const 94 while(n-- > 0 && rt==0)
96 rt = WaitForSingleObject((HANDLE)S, ms<=0?INFINITE:ms);
109 struct timespec timeToWait;
112 gettimeofday(&now,
NULL);
114 timeToWait.tv_sec = now.tv_sec + ms/1000;
115 timeToWait.tv_nsec = (now.tv_usec+1000UL*(ms%1000))*1000UL;
141 return ((WaitForSingleObject((HANDLE)S,INFINITE)==WAIT_OBJECT_0)?0:EAGAIN);
165 return (ReleaseSemaphore((HANDLE)S,n,0)?0:ERANGE);
172 pthread_cond_broadcast(&
_cond);
184 LONG V = -1; ReleaseSemaphore((HANDLE)S,0,&V);
return V;
203 void reset(
int init = 0 )
206 S = CreateSemaphore(0,init,SEM_VALUE_MAX,0);
223 #endif // USEMAPHORE_H
USemaphore(int initValue=0)
bool acquire(int n=1, int ms=0)
USemaphore(const USemaphore &S)
void operator=(const USemaphore &S)
pthread_mutex_t _waitMutex