aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2012-05-10 20:45:35 +0200
committerPieter Wuille <pieter.wuille@gmail.com>2012-05-10 22:34:49 +0200
commitf0f1b3775e5e0c7939c1131f831ce0334348ac72 (patch)
tree7b2fd009f09ea2a685556362bf1f7bed47f8f326 /src
parentca0816152d91c929b51b2f644fcb9a69797a49fa (diff)
Use polling instead of boost's broken semaphore on OSX
Diffstat (limited to 'src')
-rw-r--r--src/util.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/util.h b/src/util.h
index f90b95b9d5..15ccf82f9a 100644
--- a/src/util.h
+++ b/src/util.h
@@ -287,7 +287,47 @@ typedef CMutexLock<CCriticalSection> CCriticalBlock;
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;
+#endif
inline std::string i64tostr(int64 n)
{