diff options
author | dwight <dwight@10gen.com> | 2009-11-28 13:57:30 -0500 |
---|---|---|
committer | dwight <dwight@10gen.com> | 2009-11-28 13:57:30 -0500 |
commit | b85efc80643dd4b921d78f34cdd805ec254c777b (patch) | |
tree | b03f8f563b11c064f600fd653eb8dd4316131164 /db/concurrency.h | |
parent | fb974ef4ddbc5a1a50b2f62366b64fff082ef662 (diff) | |
download | mongo-b85efc80643dd4b921d78f34cdd805ec254c777b.tar.gz |
concurrency work
Diffstat (limited to 'db/concurrency.h')
-rw-r--r-- | db/concurrency.h | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/db/concurrency.h b/db/concurrency.h index 7ad5f18ab1f..8e4241fb270 100644 --- a/db/concurrency.h +++ b/db/concurrency.h @@ -18,12 +18,25 @@ namespace mongo { #if 0 - typedef boost::shared_mutex MongoMutex; +//#if BOOST_VERSION >= 103500 + //typedef boost::shared_mutex MongoMutex; + class MongoMutex { + boost::shared_mutex m; + public: + void lock() { + m.lock(); + } + void unlock() { m.unlock(); } + void lock_shared() { m.lock_shared(); } + void unlock_shared() { m.unlock_shared(); } + }; #else /* this will be for old versions of boost */ class MongoMutex { boost::recursive_mutex m; + int x; public: + MongoMutex() { x=0; } void lock() { #if BOOST_VERSION >= 103500 m.lock(); @@ -118,6 +131,36 @@ namespace mongo { } }; + class mongolock { + bool _writelock; + public: + mongolock(bool write) : _writelock(write) { + if( _writelock ) + dbMutex.lock(); + else + dbMutex.lock_shared(); + } + ~mongolock() { + if( _writelock ) { + dbunlocking_write(); + dbMutexInfo.leaving(); + dbMutex.unlock(); + } + else { + dbunlocking_read(); + dbMutex.unlock_shared(); + } + } + /* this unlocks, does NOT upgrade. that works for our current usage */ + void releaseAndWriteLock() { + if( !_writelock ) { + _writelock = true; + dbMutex.unlock_shared(); + dbMutex.lock(); + } + } + }; + /* use writelock and readlock instead */ struct dblock : public writelock { dblock() : writelock("") { } |