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 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"); }
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; }
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; }
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"); }
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< 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)); }
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)); }
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; }
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); }
typename enable_if< is_condition_variable_compatible< Mutex >, void >::type wait(unique_lock< Mutex >& lock) { BOOST_ASSERT(lock.owns_lock()); m_cond.wait(lock); }