summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2010-09-17 23:55:41 -0400
committerEliot Horowitz <eliot@10gen.com>2010-09-17 23:55:41 -0400
commit268a8a39dfa9ddb0401c3ab82c01ff01d28cee86 (patch)
tree4d633920edf741186e2cdab5bbe876731b2e7adf
parent417dd24161f3f97f6c18bc9dd06967be14954eef (diff)
downloadmongo-268a8a39dfa9ddb0401c3ab82c01ff01d28cee86.tar.gz
fix Future SERVER-1602
-rw-r--r--client/parallel.cpp38
-rw-r--r--client/parallel.h7
2 files changed, 18 insertions, 27 deletions
diff --git a/client/parallel.cpp b/client/parallel.cpp
index eeadb89881b..92d1b0446bb 100644
--- a/client/parallel.cpp
+++ b/client/parallel.cpp
@@ -452,37 +452,31 @@ namespace mongo {
}
bool Future::CommandResult::join(){
- while ( ! _done )
- sleepmicros( 50 );
+ _thr->join();
+ assert( _done );
return _ok;
}
- void Future::commandThread(){
- assert( _grab );
- shared_ptr<CommandResult> res = *_grab;
- _grab = 0;
-
- ScopedDbConnection conn( res->_server );
- res->_ok = conn->runCommand( res->_db , res->_cmd , res->_res );
+ void Future::commandThread( shared_ptr<CommandResult> res ){
+ setThreadName( "future" );
+
+ try {
+ ScopedDbConnection conn( res->_server );
+ res->_ok = conn->runCommand( res->_db , res->_cmd , res->_res );
+ conn.done();
+ }
+ catch ( std::exception& e ){
+ error() << "Future::commandThread exception: " << e.what() << endl;
+ res->_ok = false;
+ }
res->_done = true;
- conn.done();
}
shared_ptr<Future::CommandResult> Future::spawnCommand( const string& server , const string& db , const BSONObj& cmd ){
- shared_ptr<Future::CommandResult> res;
- res.reset( new Future::CommandResult( server , db , cmd ) );
-
- _grab = &res;
-
- boost::thread thr( Future::commandThread );
-
- while ( _grab )
- sleepmicros(2);
-
+ shared_ptr<Future::CommandResult> res( new Future::CommandResult( server , db , cmd ) );
+ res->_thr.reset( new boost::thread( boost::bind( Future::commandThread , res ) ) );
return res;
}
-
- shared_ptr<Future::CommandResult> * Future::_grab;
}
diff --git a/client/parallel.h b/client/parallel.h
index b60190aa3b0..603cfe7478b 100644
--- a/client/parallel.h
+++ b/client/parallel.h
@@ -274,7 +274,7 @@ namespace mongo {
string _db;
BSONObj _cmd;
- boost::thread _thr;
+ scoped_ptr<boost::thread> _thr;
BSONObj _res;
bool _done;
@@ -283,12 +283,9 @@ namespace mongo {
friend class Future;
};
- static void commandThread();
+ static void commandThread( shared_ptr<CommandResult> res );
static shared_ptr<CommandResult> spawnCommand( const string& server , const string& db , const BSONObj& cmd );
-
- private:
- static shared_ptr<CommandResult> * _grab;
};