本文整理汇总了C++中Mutex::GetMutex方法的典型用法代码示例。如果您正苦于以下问题:C++ Mutex::GetMutex方法的具体用法?C++ Mutex::GetMutex怎么用?C++ Mutex::GetMutex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mutex
的用法示例。
在下文中一共展示了Mutex::GetMutex方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
//----------------------------------------------------------------------
// The Wait() function atomically blocks the current thread
// waiting on the owned condition variable, and unblocks the mutex
// specified by "mutex". The waiting thread unblocks only after
// another thread calls Signal(), or Broadcast() with the same
// condition variable, or if "abstime" is valid (non-NULL) this
// function will return when the system time reaches the time
// specified in "abstime". If "abstime" is NULL this function will
// wait for an infinite amount of time for the condition variable
// to be signaled or broadcasted.
//
// The current thread re-acquires the lock on "mutex".
//----------------------------------------------------------------------
int
Condition::Wait (Mutex &mutex, const TimeValue *abstime, bool *timed_out)
{
int err = 0;
do
{
if (abstime && abstime->IsValid())
{
struct timespec abstime_ts = abstime->GetAsTimeSpec();
err = ::pthread_cond_timedwait (&m_condition, mutex.GetMutex(), &abstime_ts);
}
else
err = ::pthread_cond_wait (&m_condition, mutex.GetMutex());
} while (err == EINTR);
if (timed_out != NULL)
{
if (err == ETIMEDOUT)
*timed_out = true;
else
*timed_out = false;
}
return err;
}
示例2: SleepConditionVariableCS
int
Condition::Wait (Mutex &mutex, const TimeValue *abstime, bool *timed_out)
{
#ifdef _WIN32
DWORD wait = INFINITE;
if (abstime != NULL)
wait = tv2ms(abstime->GetAsTimeVal());
int err = SleepConditionVariableCS(&m_condition, (PCRITICAL_SECTION)&mutex,
wait);
if (timed_out != NULL)
{
if ((err == 0) && GetLastError() == ERROR_TIMEOUT)
*timed_out = true;
else
*timed_out = false;
}
return err != 0;
#else
int err = 0;
do
{
if (abstime && abstime->IsValid())
{
struct timespec abstime_ts = abstime->GetAsTimeSpec();
err = ::pthread_cond_timedwait (&m_condition, mutex.GetMutex(), &abstime_ts);
}
else
err = ::pthread_cond_wait (&m_condition, mutex.GetMutex());
} while (err == EINTR);
if (timed_out != NULL)
{
if (err == ETIMEDOUT)
*timed_out = true;
else
*timed_out = false;
}
return err;
#endif
}
示例3: Wait
void Condition::Wait(Mutex& mutex)
{
pthread_cond_wait(&cond, mutex.GetMutex());
}