// Execute the wrapped action. This locks the mutex ensuring a thread // safe action invocation. threads::thread_state_enum thread_function( threads::thread_state_ex_enum state, threads::thread_function_type f) { threads::thread_state_enum result = threads::unknown; // now lock the mutex and execute the action std::unique_lock<mutex_type> l(mtx_); // We can safely ignore this lock while checking as it is // guaranteed to be unlocked before the thread is suspended. // // If this lock is not ignored it will cause false positives as the // check for held locks is performed before this lock is unlocked. util::ignore_while_checking< std::unique_lock<mutex_type> > ignore_lock(&l); { // register our yield decorator decorate_wrapper yield_decorator( util::bind(&locking_hook::yield_function, this, util::placeholders::_1)); result = f(state); (void)yield_decorator; // silence gcc warnings } return result; }
ignore_while_checking(boost::upgrade_lock<Mutex> const* lock) : mtx_(lock->mutex()) { ignore_lock(mtx_); }
ignore_while_checking(Lock const* lock) : mtx_(lock->mutex()) { ignore_lock(mtx_); }
ignore_while_checking( boost::detail::try_lock_wrapper<Mutex> const* lock) : mtx_(lock->mutex()) { ignore_lock(mtx_); }