diff options
author | Eliot Horowitz <eliot@10gen.com> | 2010-09-17 23:39:51 -0400 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2010-09-17 23:39:51 -0400 |
commit | 54d982725d5ae29608b39905b4c89b4f373d294b (patch) | |
tree | 45387d02b3a551f81ad901deed80ce9530e15214 /client/parallel.cpp | |
parent | 384693b5948879ee866dd6c13cf3dbe1972b5198 (diff) | |
download | mongo-54d982725d5ae29608b39905b4c89b4f373d294b.tar.gz |
simplify Future and have it catch exceptions
Diffstat (limited to 'client/parallel.cpp')
-rw-r--r-- | client/parallel.cpp | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/client/parallel.cpp b/client/parallel.cpp index ab23dbb7ce2..29ea746fefb 100644 --- a/client/parallel.cpp +++ b/client/parallel.cpp @@ -462,33 +462,31 @@ namespace mongo { _server = server; _db = db; _cmd = cmd; - _done = false; } bool Future::CommandResult::join(){ - if (_done) - return _ok; - - _barrier.take(); - _barrier.put(true); // so others can take again - - assert(_done); - + _thr->join(); return _ok; } void Future::commandThread(shared_ptr<CommandResult> res){ - ScopedDbConnection conn( res->_server ); - res->_ok = conn->runCommand( res->_db , res->_cmd , res->_res ); - res->_done = true; - res->_barrier.put(true); - conn.done(); + 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; + } } shared_ptr<Future::CommandResult> Future::spawnCommand( const string& server , const string& db , const BSONObj& cmd ){ shared_ptr<Future::CommandResult> res (new Future::CommandResult( server , db , cmd )); - boost::thread thr( boost::bind(Future::commandThread, res) ); - + res->_thr.reset( new boost::thread( boost::bind(Future::commandThread, res) ) ); + return res; } |