diff options
author | Eric Milkie <milkie@10gen.com> | 2012-03-20 17:35:01 -0400 |
---|---|---|
committer | Eric Milkie <milkie@10gen.com> | 2012-03-20 17:37:45 -0400 |
commit | 0c1a6bdbe1d8aaadfdb34d71c238d96f0984227a (patch) | |
tree | 6f044cb94968541e95f75b2918384d44b2c395f8 /src/mongo/db/d_concurrency.h | |
parent | 2ba612172edcbbf4d5b04a8b21d0b53b2ece8e53 (diff) | |
download | mongo-0c1a6bdbe1d8aaadfdb34d71c238d96f0984227a.tar.gz |
implement writelocktry and readlocktry in terms of GlobalWrite and GlobalRead
This fixes replsets/auth3.js.
This change is necessary because TempRelease needs a real ScopedLock object
to operate properly, so you must go through GlobalWrite/GlobalRead.
Diffstat (limited to 'src/mongo/db/d_concurrency.h')
-rw-r--r-- | src/mongo/db/d_concurrency.h | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/src/mongo/db/d_concurrency.h b/src/mongo/db/d_concurrency.h index fa66a9c6bb1..67d00be22fb 100644 --- a/src/mongo/db/d_concurrency.h +++ b/src/mongo/db/d_concurrency.h @@ -55,18 +55,21 @@ namespace mongo { should generally not be used it is for exceptional circumstances. journaling uses it. perhaps this should go away it makes the software more complicated. */ - GlobalWrite(bool stopGreed = false); + // timeoutms is only for writelocktry -- deprecated -- do not use + GlobalWrite(bool stopGreed = false, int timeoutms = -1 ); virtual ~GlobalWrite(); void downgrade(); // W -> R bool upgrade(); // caution see notes }; - struct GlobalRead : private ScopedLock { // recursive is ok + class GlobalRead : private ScopedLock { // recursive is ok + public: bool noop; protected: void tempRelease(); void relock(); public: - GlobalRead(); + // timeoutms is only for readlocktry -- deprecated -- do not use + GlobalRead( int timeoutms = -1 ); virtual ~GlobalRead(); }; // lock this database. do not shared_lock globally first, that is handledin herein. @@ -137,6 +140,32 @@ namespace mongo { writelock(); }; + class readlocktry : boost::noncopyable { + bool _got; + scoped_ptr<Lock::GlobalRead> _dbrlock; + public: + readlocktry( int tryms ); + ~readlocktry(); + bool got() const { return _got; } + }; + + class writelocktry : boost::noncopyable { + bool _got; + scoped_ptr<Lock::GlobalWrite> _dbwlock; + public: + writelocktry( int tryms ); + ~writelocktry(); + bool got() const { return _got; } + }; + + struct readlocktryassert : public readlocktry { + readlocktryassert(int tryms) : + readlocktry(tryms) { + uassert(13142, "timeout getting readlock", got()); + } + }; + + /** parameterized choice of read or write locking */ class mongolock { scoped_ptr<readlock> r; |