Skip to content

Commit

Permalink
Revert "Revert "SERVER-695 don't destroy static global mutexes""
Browse files Browse the repository at this point in the history
This reverts commit eb7cde3.

Conflicts:

	db/instance.h
  • Loading branch information
astaple committed Mar 15, 2010
1 parent 3133059 commit c971842
Show file tree
Hide file tree
Showing 50 changed files with 204 additions and 153 deletions.
4 changes: 2 additions & 2 deletions client/connpool.cpp
Expand Up @@ -27,7 +27,7 @@ namespace mongo {
DBConnectionPool pool;

DBClientBase* DBConnectionPool::get(const string& host) {
boostlock L(poolMutex);
scoped_lock L(poolMutex);

PoolForHost *&p = pools[host];
if ( p == 0 )
Expand Down Expand Up @@ -64,7 +64,7 @@ namespace mongo {
}

void DBConnectionPool::flush(){
boostlock L(poolMutex);
scoped_lock L(poolMutex);
for ( map<string,PoolForHost*>::iterator i = pools.begin(); i != pools.end(); i++ ){
PoolForHost* p = i->second;

Expand Down
4 changes: 2 additions & 2 deletions client/connpool.h
Expand Up @@ -51,7 +51,7 @@ namespace mongo {
}
*/
class DBConnectionPool {
boost::mutex poolMutex;
mongo::mutex poolMutex;
map<string,PoolForHost*> pools; // servername -> pool
list<DBConnectionHook*> _hooks;

Expand All @@ -63,7 +63,7 @@ namespace mongo {
void release(const string& host, DBClientBase *c) {
if ( c->isFailed() )
return;
boostlock L(poolMutex);
scoped_lock L(poolMutex);
pools[host]->pool.push(c);
}
void addHook( DBConnectionHook * hook );
Expand Down
6 changes: 3 additions & 3 deletions db/client.cpp
Expand Up @@ -29,7 +29,7 @@

namespace mongo {

boost::mutex Client::clientsMutex;
mongo::mutex Client::clientsMutex;
set<Client*> Client::clients; // always be in clientsMutex when manipulating this
boost::thread_specific_ptr<Client> currentClient;

Expand All @@ -40,7 +40,7 @@ namespace mongo {
_god(0)
{
_curOp = new CurOp( this );
boostlock bl(clientsMutex);
scoped_lock bl(clientsMutex);
clients.insert(this);
}

Expand All @@ -59,7 +59,7 @@ namespace mongo {
if ( inShutdown() )
return false;
{
boostlock bl(clientsMutex);
scoped_lock bl(clientsMutex);
clients.erase(this);
}

Expand Down
6 changes: 3 additions & 3 deletions db/client.h
@@ -1,5 +1,5 @@
// client.h

// client.h

/**
* Copyright (C) 2008 10gen Inc.
*
Expand Down Expand Up @@ -42,7 +42,7 @@ namespace mongo {

class Client : boost::noncopyable {
public:
static boost::mutex clientsMutex;
static mongo::mutex clientsMutex;
static set<Client*> clients; // always be in clientsMutex when manipulating this

class GodScope {
Expand Down
16 changes: 8 additions & 8 deletions db/clientcursor.cpp
Expand Up @@ -36,7 +36,7 @@ namespace mongo {
boost::recursive_mutex ClientCursor::ccmutex;

unsigned ClientCursor::byLocSize() {
recursive_boostlock lock(ccmutex);
recursive_scoped_lock lock(ccmutex);
return byLoc.size();
}

Expand Down Expand Up @@ -73,7 +73,7 @@ namespace mongo {
assert( len > 0 && strchr(nsPrefix, '.') );

{
recursive_boostlock lock(ccmutex);
recursive_scoped_lock lock(ccmutex);

for ( CCByLoc::iterator i = byLoc.begin(); i != byLoc.end(); ++i ) {
ClientCursor *cc = i->second;
Expand All @@ -88,7 +88,7 @@ namespace mongo {

/* called every 4 seconds. millis is amount of idle time passed since the last call -- could be zero */
void ClientCursor::idleTimeReport(unsigned millis) {
recursive_boostlock lock(ccmutex);
recursive_scoped_lock lock(ccmutex);
for ( CCByLoc::iterator i = byLoc.begin(); i != byLoc.end(); ) {
CCByLoc::iterator j = i;
i++;
Expand All @@ -104,7 +104,7 @@ namespace mongo {
note this is potentially slow
*/
void ClientCursor::informAboutToDeleteBucket(const DiskLoc& b) {
recursive_boostlock lock(ccmutex);
recursive_scoped_lock lock(ccmutex);
RARELY if ( byLoc.size() > 70 ) {
log() << "perf warning: byLoc.size=" << byLoc.size() << " in aboutToDeleteBucket\n";
}
Expand All @@ -117,7 +117,7 @@ namespace mongo {

/* must call this on a delete so we clean up the cursors. */
void ClientCursor::aboutToDelete(const DiskLoc& dl) {
recursive_boostlock lock(ccmutex);
recursive_scoped_lock lock(ccmutex);

CCByLoc::iterator j = byLoc.lower_bound(dl);
CCByLoc::iterator stop = byLoc.upper_bound(dl);
Expand Down Expand Up @@ -170,7 +170,7 @@ namespace mongo {
assert( pos != -2 );

{
recursive_boostlock lock(ccmutex);
recursive_scoped_lock lock(ccmutex);
setLastLoc_inlock( DiskLoc() ); // removes us from bylocation multimap
clientCursorsById.erase(cursorid);

Expand All @@ -193,7 +193,7 @@ namespace mongo {
return;
}
{
recursive_boostlock lock(ccmutex);
recursive_scoped_lock lock(ccmutex);
setLastLoc_inlock(cl);
c->noteLocation();
}
Expand Down Expand Up @@ -269,7 +269,7 @@ namespace mongo {
}
virtual LockType locktype(){ return NONE; }
bool run(const char *dbname, BSONObj& jsobj, string& errmsg, BSONObjBuilder& result, bool fromRepl ){
recursive_boostlock lock(ClientCursor::ccmutex);
recursive_scoped_lock lock(ClientCursor::ccmutex);
result.append("byLocation_size", unsigned( ClientCursor::byLoc.size() ) );
result.append("clientCursors_size", unsigned( ClientCursor::clientCursorsById.size() ) );
return true;
Expand Down
8 changes: 4 additions & 4 deletions db/clientcursor.h
Expand Up @@ -83,7 +83,7 @@ namespace mongo {
_c = 0;
}
Pointer(long long cursorid) {
recursive_boostlock lock(ccmutex);
recursive_scoped_lock lock(ccmutex);
_c = ClientCursor::find_inlock(cursorid, true);
if( _c ) {
if( _c->_pinValue >= 100 ) {
Expand Down Expand Up @@ -113,7 +113,7 @@ namespace mongo {
{
if( !okToTimeout )
noTimeout();
recursive_boostlock lock(ccmutex);
recursive_scoped_lock lock(ccmutex);
cursorid = allocCursorId_inlock();
clientCursorsById.insert( make_pair(cursorid, this) );
}
Expand Down Expand Up @@ -155,7 +155,7 @@ namespace mongo {
}
public:
static ClientCursor* find(CursorId id, bool warn = true) {
recursive_boostlock lock(ccmutex);
recursive_scoped_lock lock(ccmutex);
ClientCursor *c = find_inlock(id, warn);
// if this asserts, your code was not thread safe - you either need to set no timeout
// for the cursor or keep a ClientCursor::Pointer in scope for it.
Expand All @@ -164,7 +164,7 @@ namespace mongo {
}

static bool erase(CursorId id) {
recursive_boostlock lock(ccmutex);
recursive_scoped_lock lock(ccmutex);
ClientCursor *cc = find_inlock(id);
if ( cc ) {
assert( cc->_pinValue < 100 ); // you can't still have an active ClientCursor::Pointer
Expand Down
1 change: 1 addition & 0 deletions db/db.cpp
Expand Up @@ -588,6 +588,7 @@ string arg_error_check(int argc, char* argv[]) {

int main(int argc, char* argv[], char *envp[] )
{
static StaticObserver staticObserver;
getcurns = ourgetns;

po::options_description general_options("General options");
Expand Down
6 changes: 3 additions & 3 deletions db/dbcommands_admin.cpp
Expand Up @@ -274,7 +274,7 @@ namespace mongo {

extern bool unlockRequested;
extern unsigned lockedForWriting;
extern boost::mutex lockedForWritingMutex;
extern mongo::mutex lockedForWritingMutex;

/*
class UnlockCommand : public Command {
Expand Down Expand Up @@ -308,7 +308,7 @@ namespace mongo {
Client::initThread("fsyncjob");
Client& c = cc();
{
boostlock lk(lockedForWritingMutex);
scoped_lock lk(lockedForWritingMutex);
lockedForWriting++;
}
readlock lk("");
Expand All @@ -323,7 +323,7 @@ namespace mongo {
sleepmillis(20);
}
{
boostlock lk(lockedForWritingMutex);
scoped_lock lk(lockedForWritingMutex);
lockedForWriting--;
}
c.shutdown();
Expand Down
2 changes: 1 addition & 1 deletion db/dbwebserver.cpp
Expand Up @@ -195,7 +195,7 @@ namespace mongo {

<< "</tr>\n";
{
boostlock bl(Client::clientsMutex);
scoped_lock bl(Client::clientsMutex);
for( set<Client*>::iterator i = Client::clients.begin(); i != Client::clients.end(); i++ ) {
Client *c = *i;
CurOp& co = *(c->curop());
Expand Down
2 changes: 1 addition & 1 deletion db/index.cpp
Expand Up @@ -79,7 +79,7 @@ namespace mongo {
}

const IndexSpec& IndexDetails::getSpec() const {
boostlock lk(NamespaceDetailsTransient::_qcMutex);
scoped_lock lk(NamespaceDetailsTransient::_qcMutex);
return NamespaceDetailsTransient::get_inlock( info.obj()["ns"].valuestr() ).getIndexSpec( this );
}

Expand Down
8 changes: 4 additions & 4 deletions db/instance.cpp
Expand Up @@ -76,7 +76,7 @@ namespace mongo {

// see FSyncCommand:
unsigned lockedForWriting;
boost::mutex lockedForWritingMutex;
mongo::mutex lockedForWritingMutex;
bool unlockRequested = false;

void inProgCmd( Message &m, DbResponse &dbresponse ) {
Expand All @@ -93,7 +93,7 @@ namespace mongo {
vector<BSONObj> vals;
{
Client& me = cc();
boostlock bl(Client::clientsMutex);
scoped_lock bl(Client::clientsMutex);
for( set<Client*>::iterator i = Client::clients.begin(); i != Client::clients.end(); i++ ) {
Client *c = *i;
if ( c == &me )
Expand Down Expand Up @@ -588,7 +588,7 @@ namespace mongo {

void recCacheCloseAll();

boost::mutex &exitMutex( *( new boost::mutex ) );
mongo::mutex exitMutex;
int numExitCalls = 0;
void shutdown();

Expand Down Expand Up @@ -616,7 +616,7 @@ namespace mongo {
void dbexit( ExitCode rc, const char *why) {
Client * c = currentClient.get();
{
boostlock lk( exitMutex );
scoped_lock lk( exitMutex );
if ( numExitCalls++ > 0 ) {
if ( numExitCalls > 5 ){
// this means something horrible has happened
Expand Down
8 changes: 4 additions & 4 deletions db/instance.h
Expand Up @@ -38,7 +38,7 @@ namespace mongo {
7 = log a few reads, and all writes.
*/
int level;
boost::mutex mutex;
mongo::mutex mutex;

DiagLog() : f(0) , level(0) { }
void init() {
Expand All @@ -65,13 +65,13 @@ namespace mongo {
}
void flush() {
if ( level ){
boostlock lk(mutex);
scoped_lock lk(mutex);
f->flush();
}
}
void write(char *data,int len) {
if ( level & 1 ){
boostlock lk(mutex);
scoped_lock lk(mutex);
f->write(data,len);
}
}
Expand All @@ -80,7 +80,7 @@ namespace mongo {
bool log = (level & 4) == 0;
OCCASIONALLY log = true;
if ( log ){
boostlock lk(mutex);
scoped_lock lk(mutex);
assert( f );
f->write(data,len);
}
Expand Down
8 changes: 4 additions & 4 deletions db/lasterror.cpp
Expand Up @@ -28,7 +28,7 @@ namespace mongo {

LastError LastError::noError;
LastErrorHolder lastError;
boost::mutex LastErrorHolder::_idsmutex;
mongo::mutex LastErrorHolder::_idsmutex;

void LastError::appendSelf( BSONObjBuilder &b ) {
if ( !valid ) {
Expand Down Expand Up @@ -75,7 +75,7 @@ namespace mongo {
if ( id == 0 )
return _tl.get();

boostlock lock(_idsmutex);
scoped_lock lock(_idsmutex);
map<int,Status>::iterator i = _ids.find( id );
if ( i == _ids.end() ){
if ( ! create )
Expand All @@ -95,7 +95,7 @@ namespace mongo {
}

void LastErrorHolder::remove( int id ){
boostlock lock(_idsmutex);
scoped_lock lock(_idsmutex);
map<int,Status>::iterator i = _ids.find( id );
if ( i == _ids.end() )
return;
Expand All @@ -121,7 +121,7 @@ namespace mongo {
return;
}

boostlock lock(_idsmutex);
scoped_lock lock(_idsmutex);
Status & status = _ids[id];
status.time = time(0);
status.lerr = le;
Expand Down
2 changes: 1 addition & 1 deletion db/lasterror.h
Expand Up @@ -100,7 +100,7 @@ namespace mongo {
time_t time;
LastError *lerr;
};
static boost::mutex _idsmutex;
static mongo::mutex _idsmutex;
map<int,Status> _ids;
} lastError;

Expand Down
4 changes: 2 additions & 2 deletions db/namespace.cpp
Expand Up @@ -609,8 +609,8 @@ namespace mongo {

/* ------------------------------------------------------------------------- */

boost::mutex NamespaceDetailsTransient::_qcMutex;
boost::mutex NamespaceDetailsTransient::_isMutex;
mongo::mutex NamespaceDetailsTransient::_qcMutex;
mongo::mutex NamespaceDetailsTransient::_isMutex;
map< string, shared_ptr< NamespaceDetailsTransient > > NamespaceDetailsTransient::_map;
typedef map< string, shared_ptr< NamespaceDetailsTransient > >::iterator ouriter;

Expand Down
6 changes: 3 additions & 3 deletions db/namespace.h
Expand Up @@ -506,12 +506,12 @@ namespace mongo {
/* IndexSpec caching */
private:
map<const IndexDetails*,IndexSpec> _indexSpecs;
static boost::mutex _isMutex;
static mongo::mutex _isMutex;
public:
const IndexSpec& getIndexSpec( const IndexDetails * details ){
IndexSpec& spec = _indexSpecs[details];
if ( ! spec._finishedInit ){
boostlock lk(_isMutex);
scoped_lock lk(_isMutex);
if ( ! spec._finishedInit ){
spec.reset( details );
assert( spec._finishedInit );
Expand All @@ -525,7 +525,7 @@ namespace mongo {
int _qcWriteCount;
map< QueryPattern, pair< BSONObj, long long > > _qcCache;
public:
static boost::mutex _qcMutex;
static mongo::mutex _qcMutex;
/* you must be in the qcMutex when calling this (and using the returned val): */
static NamespaceDetailsTransient& get_inlock(const char *ns) {
return _get(ns);
Expand Down

0 comments on commit c971842

Please sign in to comment.