本文整理汇总了C++中unique_lock::mutex方法的典型用法代码示例。如果您正苦于以下问题:C++ unique_lock::mutex方法的具体用法?C++ unique_lock::mutex怎么用?C++ unique_lock::mutex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unique_lock
的用法示例。
在下文中一共展示了unique_lock::mutex方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: wait
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());
}
示例2: wait
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);
}
示例3: lock
//! 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();
}
示例4: wait
void wait( unique_lock< mutex > & lk, Pred pred)
{
if ( ! lk)
throw lock_error();
while ( ! pred() )
wait( * lk.mutex() );
}
示例5: priv_timed_wait
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;
}
示例6:
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");
}
示例7: timed_wait
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;
}
示例8: wait
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();
}
示例9: wait
void condition_variable::wait(unique_lock<mutex> &m)
{
pthread_cond_wait(&d->c,&(m.mutex()->d->m));
}
示例10: wait
void condition_variable::wait(unique_lock<mutex> &m)
{
SleepConditionVariableCS(&d->c,&(m.mutex()->d->m),INFINITE);
}
示例11: wait
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()));
}