|
|
@ -292,7 +292,47 @@ typedef CMutexLock<CCriticalSection> CCriticalBlock; |
|
|
|
LeaveCritical(); \ |
|
|
|
LeaveCritical(); \ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef MAC_OSX |
|
|
|
|
|
|
|
// boost::interprocess::interprocess_semaphore seems to spinlock on OSX; prefer polling instead
|
|
|
|
|
|
|
|
class CSemaphore |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
private: |
|
|
|
|
|
|
|
CCriticalSection cs; |
|
|
|
|
|
|
|
int val; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public: |
|
|
|
|
|
|
|
CSemaphore(int init) : val(init) {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void wait() { |
|
|
|
|
|
|
|
do { |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
LOCK(cs); |
|
|
|
|
|
|
|
if (val>0) { |
|
|
|
|
|
|
|
val--; |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Sleep(100); |
|
|
|
|
|
|
|
} while(1); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool try_wait() { |
|
|
|
|
|
|
|
LOCK(cs); |
|
|
|
|
|
|
|
if (val>0) { |
|
|
|
|
|
|
|
val--; |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void post() { |
|
|
|
|
|
|
|
LOCK(cs); |
|
|
|
|
|
|
|
val++; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
#else |
|
|
|
typedef boost::interprocess::interprocess_semaphore CSemaphore; |
|
|
|
typedef boost::interprocess::interprocess_semaphore CSemaphore; |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
/** RAII-style semaphore lock */ |
|
|
|
/** RAII-style semaphore lock */ |
|
|
|
class CSemaphoreGrant |
|
|
|
class CSemaphoreGrant |
|
|
|