X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=blobdiff_plain;f=src%2Futil.h;h=780b9db22d67c7a56d23b15d73446c411366eea5;hp=f90b95b9d57e76d4ab8db141b7f488f2dd0a9419;hb=e10622d1297e638109bbf58c35ad008f7acbae7c;hpb=ca0816152d91c929b51b2f644fcb9a69797a49fa diff --git a/src/util.h b/src/util.h index f90b95b..780b9db 100644 --- a/src/util.h +++ b/src/util.h @@ -1,7 +1,7 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2012 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying -// file license.txt or http://www.opensource.org/licenses/mit-license.php. +// file COPYING or http://www.opensource.org/licenses/mit-license.php. #ifndef BITCOIN_UTIL_H #define BITCOIN_UTIL_H @@ -217,9 +217,11 @@ public: { printf("LOCKCONTENTION: %s\n", pszName); printf("Locker: %s:%d\n", pszFile, nLine); - } #endif lock.lock(); +#ifdef DEBUG_LOCKCONTENTION + } +#endif } } @@ -287,7 +289,47 @@ typedef CMutexLock 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) {