diff options
Diffstat (limited to 'src/mongo/util/concurrency/mutex.h')
-rw-r--r-- | src/mongo/util/concurrency/mutex.h | 92 |
1 files changed, 47 insertions, 45 deletions
diff --git a/src/mongo/util/concurrency/mutex.h b/src/mongo/util/concurrency/mutex.h index 1e21f81f392..65b0ae6b73a 100644 --- a/src/mongo/util/concurrency/mutex.h +++ b/src/mongo/util/concurrency/mutex.h @@ -38,64 +38,66 @@ namespace mongo { - /** The concept with SimpleMutex is that it is a basic lock/unlock - * with no special functionality (such as try and try - * timeout). Thus it can be implemented using OS-specific - * facilities in all environments (if desired). On Windows, - * the implementation below is faster than boost mutex. - */ +/** The concept with SimpleMutex is that it is a basic lock/unlock + * with no special functionality (such as try and try + * timeout). Thus it can be implemented using OS-specific + * facilities in all environments (if desired). On Windows, + * the implementation below is faster than boost mutex. +*/ #if defined(_WIN32) - class SimpleMutex { - MONGO_DISALLOW_COPYING(SimpleMutex); - public: - SimpleMutex() { - InitializeCriticalSection( &_cs ); - } +class SimpleMutex { + MONGO_DISALLOW_COPYING(SimpleMutex); - ~SimpleMutex() { - if ( ! StaticObserver::_destroyingStatics ) { - DeleteCriticalSection(&_cs); - } - } +public: + SimpleMutex() { + InitializeCriticalSection(&_cs); + } - void lock() { - EnterCriticalSection( &_cs ); - } - void unlock() { - LeaveCriticalSection( &_cs ); + ~SimpleMutex() { + if (!StaticObserver::_destroyingStatics) { + DeleteCriticalSection(&_cs); } + } + + void lock() { + EnterCriticalSection(&_cs); + } + void unlock() { + LeaveCriticalSection(&_cs); + } - private: - CRITICAL_SECTION _cs; - }; +private: + CRITICAL_SECTION _cs; +}; #else - class SimpleMutex { - MONGO_DISALLOW_COPYING(SimpleMutex); - public: - SimpleMutex() { - verify( pthread_mutex_init(&_lock,0) == 0 ); - } +class SimpleMutex { + MONGO_DISALLOW_COPYING(SimpleMutex); - ~SimpleMutex() { - if ( ! StaticObserver::_destroyingStatics ) { - verify( pthread_mutex_destroy(&_lock) == 0 ); - } - } +public: + SimpleMutex() { + verify(pthread_mutex_init(&_lock, 0) == 0); + } - void lock() { - verify( pthread_mutex_lock(&_lock) == 0 ); + ~SimpleMutex() { + if (!StaticObserver::_destroyingStatics) { + verify(pthread_mutex_destroy(&_lock) == 0); } + } - void unlock() { - verify( pthread_mutex_unlock(&_lock) == 0 ); - } + void lock() { + verify(pthread_mutex_lock(&_lock) == 0); + } + + void unlock() { + verify(pthread_mutex_unlock(&_lock) == 0); + } - private: - pthread_mutex_t _lock; - }; +private: + pthread_mutex_t _lock; +}; #endif -} // namespace mongo +} // namespace mongo |