当前位置: 首页>>代码示例>>C++>>正文


C++ Mutex::GetMutex方法代码示例

本文整理汇总了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;
}
开发者ID:ChaosJohn,项目名称:freebsd,代码行数:39,代码来源:Condition.cpp

示例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
}
开发者ID:carlokok,项目名称:lldb,代码行数:44,代码来源:Condition.cpp

示例3: Wait

 void Condition::Wait(Mutex& mutex)
 {
     pthread_cond_wait(&cond, mutex.GetMutex());
 }
开发者ID:aicro,项目名称:FooSql,代码行数:4,代码来源:Condition.cpp


注:本文中的Mutex::GetMutex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。