本文整理汇总了C++中unique_lock类的典型用法代码示例。如果您正苦于以下问题:C++ unique_lock类的具体用法?C++ unique_lock怎么用?C++ unique_lock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了unique_lock类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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());
}
开发者ID:jjelonek,项目名称:RIOT,代码行数:28,代码来源:condition_variable.cpp
示例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);
}
开发者ID:ktj007,项目名称:mmo,代码行数:7,代码来源:condition_variable_posix.hpp
示例3: do_job
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();
}
开发者ID:jsupancic,项目名称:AStar_Dual_Tree_HandPose,代码行数:31,代码来源:ThreadPoolCXX11.cpp
示例4:
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");
}
开发者ID:Blechhirn,项目名称:emscripten,代码行数:10,代码来源:condition_variable.cpp
示例5: wait
void wait( unique_lock< mutex > & lk, Pred pred)
{
if ( ! lk)
throw lock_error();
while ( ! pred() )
wait( * lk.mutex() );
}
开发者ID:kotbegemot,项目名称:tasks,代码行数:8,代码来源:condition.hpp
示例6: scoped_thread_id
//! 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();
}
开发者ID:nairboon,项目名称:anarchnet,代码行数:9,代码来源:async_frontend.hpp
示例7: 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;
}
开发者ID:ktj007,项目名称:mmo,代码行数:9,代码来源:condition_variable_posix.hpp
示例8: 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;
}
开发者ID:Azurami,项目名称:wagic,代码行数:12,代码来源:condition_variable.hpp
示例9: wait_for
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;
}
开发者ID:ktj007,项目名称:mmo,代码行数:12,代码来源:condition_variable_posix.hpp
示例10: g
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();
}
开发者ID:klupek,项目名称:cppcms,代码行数:22,代码来源:thread_win5.cpp
示例11: wait_until
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;
}
开发者ID:ktj007,项目名称:mmo,代码行数:13,代码来源:condition_variable_posix.hpp
示例12: readLock
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);
}
开发者ID:Senjai,项目名称:endless-sky,代码行数:23,代码来源:SpriteQueue.cpp
示例13: wait
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);
}
开发者ID:boostorg,项目名称:sync,代码行数:6,代码来源:condition_variable_windows.hpp
示例14: notify_all_at_thread_exit
void
notify_all_at_thread_exit(condition_variable& cond, unique_lock<mutex> lk)
{
__thread_local_data()->notify_all_at_thread_exit(&cond, lk.release());
}
开发者ID:Blechhirn,项目名称:emscripten,代码行数:5,代码来源:condition_variable.cpp
示例15: 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()));
}
开发者ID:Azurami,项目名称:wagic,代码行数:5,代码来源:condition_variable.hpp
示例16: timed_wait
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;
}
开发者ID:ktj007,项目名称:mmo,代码行数:6,代码来源:condition_variable_posix.hpp
示例17: wait
void condition_variable::wait(unique_lock<mutex> &m)
{
SleepConditionVariableCS(&d->c,&(m.mutex()->d->m),INFINITE);
}
开发者ID:klupek,项目名称:cppcms,代码行数:4,代码来源:thread_win6.cpp
示例18: wait
void condition_variable::wait(unique_lock<mutex> &m)
{
pthread_cond_wait(&d->c,&(m.mutex()->d->m));
}
开发者ID:klupek,项目名称:cppcms,代码行数:4,代码来源:pthread.cpp
示例19: swap
inline void swap(unique_lock<Mutex>& lhs, unique_lock<Mutex>& rhs) noexcept {
lhs.swap(rhs);
}
开发者ID:A-Paul,项目名称:RIOT,代码行数:3,代码来源:mutex.hpp
示例20: swap
inline
void swap(unique_lock<MutexT>& x, unique_lock<MutexT>& y) noexcept
{
x.swap(y);
}
开发者ID:ombre5733,项目名称:weos,代码行数:5,代码来源:_lock_guards.hpp
注:本文中的unique_lock类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论