~lock_on_exit() { if(m) { m->lock(); } }
bool try_based_timed_lock(MutexType &m, const boost::posix_time::ptime &abs_time) { //Same as lock() if(abs_time == boost::posix_time::pos_infin){ m.lock(); return true; } //Always try to lock to achieve POSIX guarantees: // "Under no circumstance shall the function fail with a timeout if the mutex // can be locked immediately. The validity of the abs_timeout parameter need not // be checked if the mutex can be locked immediately." else if(m.try_lock()){ return true; } else{ spin_wait swait; while(microsec_clock::universal_time() < abs_time){ if(m.try_lock()){ return true; } swait.yield(); } return false; } }