本文整理汇总了C++中OsTime::isNoWait方法的典型用法代码示例。如果您正苦于以下问题:C++ OsTime::isNoWait方法的具体用法?C++ OsTime::isNoWait怎么用?C++ OsTime::isNoWait使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OsTime
的用法示例。
在下文中一共展示了OsTime::isNoWait方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: acquire
// Block the task until the semaphore is acquired or the timeout expires
OsStatus OsCSemLinux::acquire(const OsTime& rTimeout)
{
struct timespec timeout;
OsStatus res;
if (rTimeout.isInfinite())
res = (pt_sem_wait(&mSemImp) == POSIX_OK) ? OS_SUCCESS : OS_BUSY;
else if (rTimeout.isNoWait())
res = (pt_sem_trywait(&mSemImp) == POSIX_OK) ? OS_SUCCESS : OS_BUSY;
else
{
OsUtilLinux::cvtOsTimeToTimespec(rTimeout, &timeout);
res = (pt_sem_timedwait(&mSemImp, &timeout) == POSIX_OK) ? OS_SUCCESS : OS_WAIT_TIMEOUT;
}
#ifdef OS_CSEM_DEBUG
if (res == OS_SUCCESS)
{
updateAcquireStats();
}
#endif
#ifdef OS_SYNC_DEBUG
if (res == OS_SUCCESS)
{
mSyncCrumbs.dropCrumb(pthread_self(), crumbAcquired);
}
#endif
return res;
}
示例2: acquire
// Block the task until the mutex is acquired or the timeout expires
OsStatus OsMutexLinux::acquire(const OsTime& rTimeout)
{
struct timespec timeout;
OsStatus status;
if(rTimeout.isInfinite())
{
status = (pt_mutex_lock(&mMutexImp) == POSIX_OK) ? OS_SUCCESS : OS_BUSY;
}
else if(rTimeout.isNoWait())
{
status = (pt_mutex_trylock(&mMutexImp) == POSIX_OK) ? OS_SUCCESS : OS_BUSY;
}
else
{
OsUtilLinux::cvtOsTimeToTimespec(rTimeout, &timeout);
status = (pt_mutex_timedlock(&mMutexImp, &timeout) == POSIX_OK)
? OS_SUCCESS : OS_WAIT_TIMEOUT;
}
#ifdef OS_SYNC_DEBUG
if (status == OS_SUCCESS)
{
mSyncCrumbs.dropCrumb(pthread_self(), crumbAcquired);
}
#endif
return status;
}