Fixed PIConditionVariable timeout bug on Linux
This commit is contained in:
@@ -90,7 +90,7 @@ bool PIConditionVariable::waitFor(PIMutex &lk, int timeoutMs) {
|
||||
#ifdef WINDOWS
|
||||
isNotTimeout = SleepConditionVariableCS(&PRIVATE->nativeHandle, (PCRITICAL_SECTION)lk.handle(), timeoutMs) != 0;
|
||||
#else
|
||||
timespec abstime = {.tv_sec = timeoutMs / 1000, .tv_nsec = timeoutMs * 1000 * 1000};
|
||||
timespec abstime = {.tv_sec = timeoutMs / 1000, .tv_nsec = timeoutMs % (int)1e6 * (int)1e6};
|
||||
isNotTimeout = pthread_cond_timedwait(&PRIVATE->nativeHandle, (pthread_mutex_t*)lk.handle(), &abstime) == 0;
|
||||
#endif
|
||||
if (PRIVATE->isDestroying) return false;
|
||||
@@ -105,17 +105,16 @@ bool PIConditionVariable::waitFor(PIMutex& lk, int timeoutMs, const std::functio
|
||||
isCondition = condition();
|
||||
if (isCondition) break;
|
||||
#ifdef WINDOWS
|
||||
WINBOOL isTimeout = SleepConditionVariableCS(
|
||||
bool isTimeout = SleepConditionVariableCS(
|
||||
&PRIVATE->nativeHandle,
|
||||
(PCRITICAL_SECTION)lk.handle(),
|
||||
timeoutMs - (int)measurer.elapsed_m());
|
||||
if (isTimeout == 0) return false;
|
||||
timeoutMs - (int)measurer.elapsed_m()) == 0;
|
||||
#else
|
||||
int timeoutCurr = timeoutMs - (int)measurer.elapsed_m();
|
||||
timespec abstime = {.tv_sec = timeoutCurr / 1000, .tv_nsec = timeoutCurr * 1000 * 1000};
|
||||
bool isTimeout = pthread_cond_timedwait(&PRIVATE->nativeHandle, (pthread_mutex_t*)lk.handle(), &abstime) == 0;
|
||||
if (isTimeout) return false;
|
||||
timespec abstime = {.tv_sec = timeoutCurr / 1000, .tv_nsec = timeoutCurr % (int)1e6 * (int)1e6};
|
||||
bool isTimeout = pthread_cond_timedwait(&PRIVATE->nativeHandle, (pthread_mutex_t*)lk.handle(), &abstime) != 0;
|
||||
#endif
|
||||
if (isTimeout) return false;
|
||||
if (PRIVATE->isDestroying) return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user