diff options
Diffstat (limited to 'src/mongo/util/concurrency/simplerwlock.h')
-rw-r--r-- | src/mongo/util/concurrency/simplerwlock.h | 69 |
1 files changed, 39 insertions, 30 deletions
diff --git a/src/mongo/util/concurrency/simplerwlock.h b/src/mongo/util/concurrency/simplerwlock.h index 8a8b3171ec9..4673f799f8c 100644 --- a/src/mongo/util/concurrency/simplerwlock.h +++ b/src/mongo/util/concurrency/simplerwlock.h @@ -35,42 +35,51 @@ namespace mongo { - /** separated out as later the implementation of this may be different than RWLock, - depending on OS, as there is no upgrade etc. facility herein. - */ - class SimpleRWLock { - MONGO_DISALLOW_COPYING(SimpleRWLock); +/** separated out as later the implementation of this may be different than RWLock, + depending on OS, as there is no upgrade etc. facility herein. +*/ +class SimpleRWLock { + MONGO_DISALLOW_COPYING(SimpleRWLock); #if defined(NTDDI_VERSION) && defined(NTDDI_WIN7) && (NTDDI_VERSION >= NTDDI_WIN7) - SRWLOCK _lock; + SRWLOCK _lock; #else - RWLockBase m; + RWLockBase m; #endif #if defined(_WIN32) && defined(MONGO_CONFIG_DEBUG_BUILD) - AtomicUInt32 shares; - ThreadLocalValue<int> s; - unsigned tid; + AtomicUInt32 shares; + ThreadLocalValue<int> s; + unsigned tid; #endif +public: + const std::string name; + SimpleRWLock(StringData name = ""); + void lock(); + void unlock(); + void lock_shared(); + void unlock_shared(); + class Shared { + MONGO_DISALLOW_COPYING(Shared); + SimpleRWLock& _r; + public: - const std::string name; - SimpleRWLock(StringData name = "" ); - void lock(); - void unlock(); - void lock_shared(); - void unlock_shared(); - class Shared { - MONGO_DISALLOW_COPYING(Shared); - SimpleRWLock& _r; - public: - Shared(SimpleRWLock& rwlock) : _r(rwlock) {_r.lock_shared(); } - ~Shared() { _r.unlock_shared(); } - }; - class Exclusive { - MONGO_DISALLOW_COPYING(Exclusive); - SimpleRWLock& _r; - public: - Exclusive(SimpleRWLock& rwlock) : _r(rwlock) {_r.lock(); } - ~Exclusive() { _r.unlock(); } - }; + Shared(SimpleRWLock& rwlock) : _r(rwlock) { + _r.lock_shared(); + } + ~Shared() { + _r.unlock_shared(); + } }; + class Exclusive { + MONGO_DISALLOW_COPYING(Exclusive); + SimpleRWLock& _r; + public: + Exclusive(SimpleRWLock& rwlock) : _r(rwlock) { + _r.lock(); + } + ~Exclusive() { + _r.unlock(); + } + }; +}; } |