Mercurial > hg > bitcoin
changeset 2496:8904ba49ffee draft
Use polling instead of boost's broken semaphore on OSX
author | Pieter Wuille <pieter.wuille@gmail.com> |
---|---|
date | Thu, 10 May 2012 20:45:35 +0200 |
parents | 8496362c2004 |
children | b570f6f9e37b |
files | src/util.h |
diffstat | 1 files changed, 40 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/util.h +++ b/src/util.h @@ -287,7 +287,47 @@ 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) {