mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
optimization: avoid an extra thread local lookup on locks
This commit is contained in:
parent
4c4349c696
commit
80ee773a16
@ -256,21 +256,20 @@ namespace mongo {
|
||||
return c->toString();
|
||||
}
|
||||
|
||||
void curopWaitingForLock( int type ){
|
||||
Client* curopWaitingForLock( int type ){
|
||||
Client * c = currentClient.get();
|
||||
assert( c );
|
||||
CurOp * co = c->curop();
|
||||
if ( co ){
|
||||
co->waitingForLock( type );
|
||||
}
|
||||
return c;
|
||||
}
|
||||
void curopGotLock(){
|
||||
Client * c = currentClient.get();
|
||||
void curopGotLock(Client *c){
|
||||
assert(c);
|
||||
CurOp * co = c->curop();
|
||||
if ( co ){
|
||||
if ( co )
|
||||
co->gotLock();
|
||||
}
|
||||
}
|
||||
|
||||
CurOp::~CurOp(){
|
||||
@ -278,7 +277,6 @@ namespace mongo {
|
||||
scoped_lock bl(Client::clientsMutex);
|
||||
_client->_curOp = _wrapped;
|
||||
}
|
||||
|
||||
_client = 0;
|
||||
}
|
||||
|
||||
|
@ -38,8 +38,9 @@ namespace mongo {
|
||||
string sayClientState();
|
||||
bool haveClient();
|
||||
|
||||
void curopWaitingForLock( int type );
|
||||
void curopGotLock();
|
||||
class Client;
|
||||
Client* curopWaitingForLock( int type );
|
||||
void curopGotLock(Client*);
|
||||
|
||||
/* mutex time stats */
|
||||
class MutexInfo {
|
||||
|
@ -53,13 +53,13 @@ namespace mongo {
|
||||
|
||||
_state.set(1);
|
||||
|
||||
curopWaitingForLock( 1 ); // stats
|
||||
Client *c = curopWaitingForLock( 1 ); // stats
|
||||
_m.lock();
|
||||
curopGotLock();
|
||||
curopGotLock(c);
|
||||
|
||||
_minfo.entered();
|
||||
|
||||
MongoFile::lockAll();
|
||||
MongoFile::lockAll(); // for _DEBUG validation -- a no op for release build
|
||||
}
|
||||
|
||||
// try write lock
|
||||
@ -67,9 +67,9 @@ namespace mongo {
|
||||
if ( _writeLockedAlready() )
|
||||
return true;
|
||||
|
||||
curopWaitingForLock( 1 );
|
||||
Client *c = curopWaitingForLock( 1 );
|
||||
bool got = _m.lock_try( millis );
|
||||
curopGotLock();
|
||||
curopGotLock(c);
|
||||
|
||||
if ( got ){
|
||||
_minfo.entered();
|
||||
@ -128,9 +128,9 @@ namespace mongo {
|
||||
}
|
||||
}
|
||||
_state.set(-1);
|
||||
curopWaitingForLock( -1 );
|
||||
Client *c = curopWaitingForLock( -1 );
|
||||
_m.lock_shared();
|
||||
curopGotLock();
|
||||
curopGotLock(c);
|
||||
}
|
||||
|
||||
// try read lock
|
||||
@ -142,6 +142,10 @@ namespace mongo {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* [dm] should there be
|
||||
Client *c = curopWaitingForLock( 1 );
|
||||
here? i think so. seems to be missing.
|
||||
*/
|
||||
bool got = _m.lock_shared_try( millis );
|
||||
if ( got )
|
||||
_state.set(-1);
|
||||
|
Loading…
Reference in New Issue
Block a user