Beispiel #1
0
void condition_variable::wait(unique_lock<mutex>& lock) noexcept {
#ifdef NOEXCEPTIONS
  lock.owns_lock();
#else
  if (!lock.owns_lock()) {
    throw std::system_error(
      std::make_error_code(std::errc::operation_not_permitted),
      "Mutex not locked.");
  }
#endif
  priority_queue_node_t n;
  n.priority = sched_active_thread->priority;
  n.data = sched_active_pid;
  n.next = NULL;
  // the signaling thread may not hold the mutex, the queue is not thread safe
  unsigned old_state = disableIRQ();
  priority_queue_add(&m_queue, &n);
  restoreIRQ(old_state);
  mutex_unlock_and_sleep(lock.mutex()->native_handle());
  if (n.data != -1u) {
    // on signaling n.data is set to -1u
    // if it isn't set, then the wakeup is either spurious or a timer wakeup
    old_state = disableIRQ();
    priority_queue_remove(&m_queue, &n);
    restoreIRQ(old_state);
  }
  mutex_lock(lock.mutex()->native_handle());
}
 typename enable_if< is_condition_variable_compatible< Mutex >, void >::type wait(unique_lock< Mutex >& lock, Predicate pred)
 {
     BOOST_ASSERT(lock.owns_lock());
     pthread_mutex_t* const mtx = lock.mutex()->native_handle();
     while (!pred())
         this->priv_wait(mtx);
 }
 void ThreadPool::do_job(ThreadPool::TaskType& task, unique_lock< mutex >& exclusion)
 {
   exclusion.unlock();
   //__sync_synchronize();
   auto start = std::chrono::system_clock::now();
   string account = task.account;
   auto task_future = task.task.get_future();
   task.task();
   try
   {
     task_future.get();
   }
   catch(std::exception&e)
   {
     log_file << "Exception thrown in job: " << e.what() << endl;
     breakpoint();
   }
   catch(...)
   {
     log_file << "Exception thrown... but it's a mystery... results undefined" << endl;
     breakpoint();
   }
   auto end = std::chrono::system_clock::now();
   int elapsed_seconds = std::chrono::duration_cast<std::chrono::seconds>
                         (end-start).count();
   //atomic_thread_fence(std::memory_order_seq_cst);
   //__sync_synchronize();
   exclusion.lock();
   accounts[account] += elapsed_seconds;
   work_queue_changed.notify_all();
 }
void
condition_variable::wait(unique_lock<mutex>& lk)
{
    if (!lk.owns_lock())
        __throw_system_error(EPERM,
                                  "condition_variable::wait: mutex not locked");
    int ec = pthread_cond_wait(&__cv_, lk.mutex()->native_handle());
    if (ec)
        __throw_system_error(ec, "condition_variable wait failed");
}
void
condition_variable::__do_timed_wait(unique_lock<mutex>& lk,
               chrono::time_point<chrono::system_clock, chrono::nanoseconds> tp)
{
    using namespace chrono;
    if (!lk.owns_lock())
        __throw_system_error(EPERM,
                            "condition_variable::timed wait: mutex not locked");
    nanoseconds d = tp.time_since_epoch();
    timespec ts;
    seconds s = duration_cast<seconds>(d);
    ts.tv_sec = static_cast<decltype(ts.tv_sec)>(s.count());
    ts.tv_nsec = static_cast<decltype(ts.tv_nsec)>((d - s).count());
    int ec = pthread_cond_timedwait(&__cv_, lk.mutex()->native_handle(), &ts);
    if (ec != 0 && ec != ETIMEDOUT)
        __throw_system_error(ec, "condition_variable timed_wait failed");
}
Beispiel #6
0
	void wait( unique_lock< mutex > & lk, Pred pred)
	{
		if ( ! lk)
			throw lock_error();

		while ( ! pred() )
			wait( * lk.mutex() );
	}
Beispiel #7
0
 //! Initializing constructor
 scoped_thread_id(unique_lock< frontend_mutex_type >& l, condition_variable_any& cond, thread::id& tid, bool volatile& sr)
     : m_Mutex(*l.mutex()), m_Cond(cond), m_ThreadID(tid), m_StopRequested(sr)
 {
     unique_lock< frontend_mutex_type > lock(move(l));
     if (m_ThreadID != thread::id())
         BOOST_LOG_THROW_DESCR(unexpected_call, "Asynchronous sink frontend already runs a record feeding thread");
     m_ThreadID = this_thread::get_id();
 }
 sync::cv_status priv_timed_wait(unique_lock< Mutex >& lock, sync::detail::system_time_point const& t)
 {
     int const res = sync::detail::posix::pthread_cond_timedwait(&m_cond, lock.mutex()->native_handle(), &t.get());
     if (res == ETIMEDOUT)
         return sync::cv_status::timeout;
     else if (res != 0)
         BOOST_SYNC_DETAIL_THROW(wait_error, (res)("boost::sync::condition_variable timedwait failed in pthread_cond_timedwait"));
     return sync::cv_status::no_timeout;
 }
Beispiel #9
0
 inline bool condition_variable::timed_wait(unique_lock<mutex>& m,boost::system_time const& wait_until)
 {
     detail::interruption_checker check_for_interruption(&cond);
     struct timespec const timeout=detail::get_timespec(wait_until);
     int const cond_res=pthread_cond_timedwait(&cond,m.mutex()->native_handle(),&timeout);
     if(cond_res==ETIMEDOUT)
     {
         return false;
     }
     BOOST_ASSERT(!cond_res);
     return true;
 }
Beispiel #10
0
 typename enable_if< mpl::and_< detail::is_time_tag_of< Duration, detail::time_duration_tag >, is_condition_variable_compatible< Mutex > >, bool >::type
 wait_for(unique_lock< Mutex >& lock, Duration const& rel_time, Predicate pred)
 {
     BOOST_ASSERT(lock.owns_lock());
     sync::detail::system_time_point abs_timeout = sync::detail::system_time_point::now() + sync::detail::time_traits< Duration >::to_sync_unit(rel_time);
     while (!pred())
     {
         if (this->priv_timed_wait(lock, abs_timeout) != sync::cv_status::no_timeout)
             return pred();
     }
     return true;
 }
Beispiel #11
0
	void condition_variable::wait(unique_lock<mutex> &m)
	{
		details::event ev;
		
		{
			booster::unique_lock<booster::mutex> g(d->lock);
			m.mutex()->unlock();
			if(d->first == 0) {
				d->first = d->last = &ev;
			}
			else {
				d->last->next = &ev;
				d->last = &ev;
			}
	
		}
		
		ev.wait();
		
		m.mutex()->lock();

	}
Beispiel #12
0
 typename enable_if< mpl::and_< detail::is_time_tag_of< TimePoint, detail::time_point_tag >, is_condition_variable_compatible< Mutex > >, bool >::type
 wait_until(unique_lock< Mutex >& lock, TimePoint const& abs_time, Predicate pred)
 {
     BOOST_ASSERT(lock.owns_lock());
     typedef typename sync::detail::time_traits< TimePoint >::unit_type unit_type;
     unit_type abs_timeout = sync::detail::time_traits< TimePoint >::to_sync_unit(abs_time);
     while (!pred())
     {
         if (this->priv_timed_wait(lock, abs_timeout) != sync::cv_status::no_timeout)
             return pred();
     }
     return true;
 }
Beispiel #13
0
double SpriteQueue::DoLoad(unique_lock<mutex> &lock) const
{
	for(int i = 0; !toLoad.empty() && i < 30; ++i)
	{
		Item item = toLoad.front();
		toLoad.pop();
		
		lock.unlock();
		
		item.sprite->AddFrame(item.frame, item.image, item.mask);
		
		lock.lock();
		++completed;
	}
	
	// Wait until we have completed loading of as many sprites as we have added.
	// The value of "added" is protected by readMutex.
	unique_lock<mutex> readLock(readMutex);
	// Special cases: we're bailing out, or we are done.
	if(added <= 0 || added == completed)
		return 1.;
	return static_cast<double>(completed) / static_cast<double>(added);
}
Beispiel #14
0
 typename enable_if< is_condition_variable_compatible< Mutex >, void >::type wait(unique_lock< Mutex >& lock)
 {
     BOOST_ASSERT(lock.owns_lock());
     this->priv_wait(lock.mutex()->native_handle());
 }
 typename enable_if< is_condition_variable_compatible< Mutex >, void >::type wait(unique_lock< Mutex >& lock, Predicate pred)
 {
     BOOST_ASSERT(lock.owns_lock());
     while (!pred())
         m_cond.wait(lock);
 }
Beispiel #16
0
	void wait( unique_lock< mutex > & lk)
	{
		if ( ! lk)
			throw lock_error();
		wait( * lk.mutex() );
	}
void
notify_all_at_thread_exit(condition_variable& cond, unique_lock<mutex> lk)
{
    __thread_local_data()->notify_all_at_thread_exit(&cond, lk.release());
}
Beispiel #18
0
 inline void condition_variable::wait(unique_lock<mutex>& m)
 {
     detail::interruption_checker check_for_interruption(&cond);
     BOOST_VERIFY(!pthread_cond_wait(&cond,m.mutex()->native_handle()));
 }
Beispiel #19
0
 typename enable_if_c< sync::detail::time_traits< Time >::is_specialized && is_condition_variable_compatible< Mutex >::value, bool >::type
 timed_wait(unique_lock< Mutex >& lock, Time const& t)
 {
     BOOST_ASSERT(lock.owns_lock());
     return priv_timed_wait(lock, sync::detail::time_traits< Time >::to_sync_unit(t)) == sync::cv_status::no_timeout;
 }
Beispiel #20
0
	void condition_variable::wait(unique_lock<mutex> &m)
	{
		SleepConditionVariableCS(&d->c,&(m.mutex()->d->m),INFINITE);
	}
 typename enable_if< is_condition_variable_compatible< Mutex >, void >::type wait(unique_lock< Mutex >& lock)
 {
     BOOST_ASSERT(lock.owns_lock());
     m_cond.wait(lock);
 }
Beispiel #22
0
	void condition_variable::wait(unique_lock<mutex> &m)
	{
		pthread_cond_wait(&d->c,&(m.mutex()->d->m));
	}
Beispiel #23
0
 typename enable_if< mpl::and_< detail::is_time_tag_of< Duration, detail::time_duration_tag >, is_condition_variable_compatible< Mutex > >, sync::cv_status >::type
 wait_for(unique_lock< Mutex >& lock, Duration const& rel_time)
 {
     BOOST_ASSERT(lock.owns_lock());
     return priv_timed_wait(lock, sync::detail::time_traits< Duration >::to_sync_unit(rel_time));
 }
Beispiel #24
0
 typename enable_if< mpl::and_< detail::is_time_tag_of< TimePoint, detail::time_point_tag >, is_condition_variable_compatible< Mutex > >, sync::cv_status >::type
 wait_until(unique_lock< Mutex >& lock, TimePoint const& abs_time)
 {
     BOOST_ASSERT(lock.owns_lock());
     return priv_timed_wait(lock, sync::detail::time_traits< TimePoint >::to_sync_unit(abs_time));
 }
Beispiel #25
0
inline void swap(unique_lock<Mutex>& lhs, unique_lock<Mutex>& rhs) noexcept {
  lhs.swap(rhs);
}
Beispiel #26
0
inline
void swap(unique_lock<MutexT>& x, unique_lock<MutexT>& y) noexcept
{
    x.swap(y);
}