/** \brief Clean up privileged jobs if we're a privileged thread.
 *
 * Ensures that a privileged job can't queue up other privileged jobs that would potentially create deadlocks.
 *
 * \param pfunctor Task to execute.
 * \param scope Previously created scoped lock.
 * \param tid Id of this thread.
 * \return True if cleaned up the queue, false if not.
 */
static bool cleanup_privileged(const Task &pfunctor, boost::mutex::scoped_lock &pscope, boost::thread::id tid)
{
  if(!is_primary_thread(tid))
  {
    return false;
  }
  while(inner_run_privileged(pscope));
  pscope.unlock();
  pfunctor();
  pscope.lock();
  return true;
}
/** \brief Clean up important jobs if we're a normal thread.
 *
 * Ensured that an important job can't queue up other important jobs that could potentially create deadlocks.
 *
 * \param pfunctor Task to execute.
 * \param scope Previously created scoped lock.
 * \param tid Id of this thread.
 * \return True if cleaned up the queue, false if not.
 */
static bool cleanup_important(const Task &pfunctor, boost::mutex::scoped_lock &pscope, boost::thread::id tid)
{
  if(threads.end() == threads.find(tid))
  {
    return false;
  }
  while(inner_run_important(pscope));
  pscope.unlock();
  pfunctor();
  pscope.lock();
  return true;
}
/** \brief Inner task running, privileged tasks.
 *
 * \param tlist Task list.
 * \param scope Previously created scoped lock.
 * \return True if executed something, false if not.
 */
static bool inner_run_privileged(boost::mutex::scoped_lock &pscope)
{
  if(tasks_privileged.empty())
  {
    return false;
  }
  Task functor = tasks_privileged.get();
  pscope.unlock();
  functor();
  pscope.lock();
  return true;
}
/** \brief Inner task running, important (promised) tasks.
 *
 * \param pscope Previously created scoped lock.
 * \return True if executed something, false if not.
 */
static bool inner_run_important(boost::mutex::scoped_lock &pscope)
{
  if(tasks_important.empty())
  {
    return false;
  }
  Promise *promise = tasks_important.get();
  pscope.unlock();
  promise->task();
  pscope.lock();
  return true;
}
示例#5
0
 ~Imp() {
   m_sl->unlock();
   delete m_sl;
 }
inline void
boost_threaded_monitor::unlock() {
	lock_.unlock();
}