From 0ca01a91ae0a3562e54c226e7b9512feb2ea83d0 Mon Sep 17 00:00:00 2001 From: Antonin Kral Date: Thu, 25 Mar 2010 19:21:32 +0100 Subject: Imported Upstream version 1.4.0 --- scripting/engine.cpp | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) (limited to 'scripting/engine.cpp') diff --git a/scripting/engine.cpp b/scripting/engine.cpp index dc088fb..cc245b6 100644 --- a/scripting/engine.cpp +++ b/scripting/engine.cpp @@ -164,9 +164,12 @@ namespace mongo { _loadedVersion = _lastVersion; string coll = _localDBName + ".system.js"; - + static DBClientBase * db = createDirectClient(); auto_ptr c = db->query( coll , Query() ); + + set thisTime; + while ( c->more() ){ BSONObj o = c->next(); @@ -177,6 +180,26 @@ namespace mongo { uassert( 10210 , "value has to be set" , v.type() != EOO ); setElement( n.valuestr() , v ); + + thisTime.insert( n.valuestr() ); + _storedNames.insert( n.valuestr() ); + + } + + // --- remove things from scope that were removed + + list toremove; + + for ( set::iterator i=_storedNames.begin(); i!=_storedNames.end(); i++ ){ + string n = *i; + if ( thisTime.count( n ) == 0 ) + toremove.push_back( n ); + } + + for ( list::iterator i=toremove.begin(); i!=toremove.end(); i++ ){ + string n = *i; + _storedNames.erase( n ); + execSetup( (string)"delete " + n , "clean up scope" ); } } @@ -220,7 +243,7 @@ namespace mongo { } void done( const string& pool , Scope * s ){ - boostlock lk( _mutex ); + scoped_lock lk( _mutex ); list & l = _pools[pool]; if ( l.size() > 10 ){ delete s; @@ -232,7 +255,7 @@ namespace mongo { } Scope * get( const string& pool ){ - boostlock lk( _mutex ); + scoped_lock lk( _mutex ); list & l = _pools[pool]; if ( l.size() == 0 ) return 0; @@ -260,7 +283,7 @@ namespace mongo { private: PoolToScopes _pools; - boost::mutex _mutex; + mongo::mutex _mutex; int _magic; }; @@ -395,5 +418,8 @@ namespace mongo { } } + void ( *ScriptEngine::_connectCallback )( DBClientWithCommands & ) = 0; + ScriptEngine * globalScriptEngine; } + \ No newline at end of file -- cgit v1.2.3