From 0ad0c09511a04ebe837f2acb859d47f2aa4e038a Mon Sep 17 00:00:00 2001 From: Antonin Kral Date: Fri, 24 Sep 2010 19:01:03 +0200 Subject: Imported Upstream version 1.6.3 --- client/parallel.cpp | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) (limited to 'client/parallel.cpp') diff --git a/client/parallel.cpp b/client/parallel.cpp index eeadb89..92d1b04 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 res = *_grab; - _grab = 0; - - ScopedDbConnection conn( res->_server ); - res->_ok = conn->runCommand( res->_db , res->_cmd , res->_res ); + void Future::commandThread( shared_ptr 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::spawnCommand( const string& server , const string& db , const BSONObj& cmd ){ - shared_ptr res; - res.reset( new Future::CommandResult( server , db , cmd ) ); - - _grab = &res; - - boost::thread thr( Future::commandThread ); - - while ( _grab ) - sleepmicros(2); - + shared_ptr res( new Future::CommandResult( server , db , cmd ) ); + res->_thr.reset( new boost::thread( boost::bind( Future::commandThread , res ) ) ); return res; } - - shared_ptr * Future::_grab; } -- cgit v1.2.3