File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -292,7 +292,47 @@ typedef CMutexLock<CCriticalSection> CCriticalBlock;
292
292
LeaveCritical (); \
293
293
}
294
294
295
+ #ifdef MAC_OSX
296
+ // boost::interprocess::interprocess_semaphore seems to spinlock on OSX; prefer polling instead
297
+ class CSemaphore
298
+ {
299
+ private:
300
+ CCriticalSection cs;
301
+ int val;
302
+
303
+ public:
304
+ CSemaphore (int init) : val(init) {}
305
+
306
+ void wait () {
307
+ do {
308
+ {
309
+ LOCK (cs);
310
+ if (val>0 ) {
311
+ val--;
312
+ return ;
313
+ }
314
+ }
315
+ Sleep (100 );
316
+ } while (1 );
317
+ }
318
+
319
+ bool try_wait () {
320
+ LOCK (cs);
321
+ if (val>0 ) {
322
+ val--;
323
+ return true ;
324
+ }
325
+ return false ;
326
+ }
327
+
328
+ void post () {
329
+ LOCK (cs);
330
+ val++;
331
+ }
332
+ };
333
+ #else
295
334
typedef boost::interprocess::interprocess_semaphore CSemaphore;
335
+ #endif
296
336
297
337
/* * RAII-style semaphore lock */
298
338
class CSemaphoreGrant
You can’t perform that action at this time.
0 commit comments