summaryrefslogtreecommitdiff
path: root/src/mongo/db/db.h
diff options
context:
space:
mode:
authorDwight <dwight@10gen.com>2012-02-07 12:42:50 -0500
committerDwight <dwight@10gen.com>2012-02-07 12:42:50 -0500
commit27c85880962d92b187d5f71561b4e3bf7f0c62fd (patch)
tree810be3c87dbf7b2da11f36b87744fd9239d93d6d /src/mongo/db/db.h
parent79b694a785a84b2394fa4699cc47e34ff888f6e2 (diff)
downloadmongo-27c85880962d92b187d5f71561b4e3bf7f0c62fd.tar.gz
SERVER-4328 temprelease implementation
only for global read or write (R or W) for now asserts for granular (once that is flipped on)
Diffstat (limited to 'src/mongo/db/db.h')
-rw-r--r--src/mongo/db/db.h56
1 files changed, 20 insertions, 36 deletions
diff --git a/src/mongo/db/db.h b/src/mongo/db/db.h
index 7c3a5d0c889..dd7818b6428 100644
--- a/src/mongo/db/db.h
+++ b/src/mongo/db/db.h
@@ -26,64 +26,53 @@
namespace mongo {
+ // todo: relocked is being called when there was no unlock below.
+ // that is weird.
+
struct dbtemprelease {
Client::Context * _context;
- int _locktype;
-
+ scoped_ptr<Lock::TempRelease> tr;
dbtemprelease() {
const Client& c = cc();
_context = c.getContext();
- _locktype = d.dbMutex.getState();
- assert( _locktype );
-
- if ( _locktype > 0 ) {
- massert( 10298 , "can't temprelease nested write lock", _locktype == 1);
- if ( _context ) _context->unlocked();
- d.dbMutex.unlock();
- }
- else {
- massert( 10299 , "can't temprelease nested read lock", _locktype == -1);
- if ( _context ) _context->unlocked();
- d.dbMutex.unlock_shared();
+ assert( Lock::isLocked() );
+ massert(10298 , "can't temprelease nested lock", !Lock::nested());
+ if ( _context ) {
+ _context->unlocked();
}
-
+ tr.reset(new Lock::TempRelease);
verify( 14814 , c.curop() );
c.curop()->yielded();
-
}
~dbtemprelease() {
- if ( _locktype > 0 )
- d.dbMutex.lock();
- else
- d.dbMutex.lock_shared();
-
- if ( _context ) _context->relocked();
+ tr.reset();
+ if ( _context )
+ _context->relocked();
}
};
/** must be write locked
no assert (and no release) if nested write lock
- a lot like dbtempreleasecond but no malloc so should be a tiny bit faster
+ a lot like dbtempreleasecond, eliminate?
*/
struct dbtempreleasewritelock {
Client::Context * _context;
int _locktype;
+ scoped_ptr<Lock::TempRelease> tr;
dbtempreleasewritelock() {
const Client& c = cc();
_context = c.getContext();
- _locktype = d.dbMutex.getState();
- assert( _locktype >= 1 );
- if( _locktype > 1 )
- return; // nested
+ assert( Lock::isW() );
+ if( Lock::nested() )
+ return;
if ( _context )
_context->unlocked();
- d.dbMutex.unlock();
+ tr.reset(new Lock::TempRelease);
verify( 14845 , c.curop() );
c.curop()->yielded();
}
~dbtempreleasewritelock() {
- if ( _locktype == 1 )
- d.dbMutex.lock();
+ tr.reset();
if ( _context )
_context->relocked();
}
@@ -94,22 +83,17 @@ namespace mongo {
*/
struct dbtempreleasecond {
dbtemprelease * real;
- int locktype;
-
dbtempreleasecond() {
real = 0;
- locktype = d.dbMutex.getState();
- if ( locktype == 1 || locktype == -1 )
+ if( Lock::isLocked() )
real = new dbtemprelease();
}
-
~dbtempreleasecond() {
if ( real ) {
delete real;
real = 0;
}
}
-
bool unlocked() {
return real != 0;
}