Merge pull request 'Fixed PIConditionVariable timeout bug on Linux' (#33) from cond_fix into master
Reviewed-on: https://git.shs.tools/SHS/pip/pulls/33
This commit was merged in pull request #33.
This commit is contained in:
@@ -90,7 +90,7 @@ bool PIConditionVariable::waitFor(PIMutex &lk, int timeoutMs) {
|
|||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
isNotTimeout = SleepConditionVariableCS(&PRIVATE->nativeHandle, (PCRITICAL_SECTION)lk.handle(), timeoutMs) != 0;
|
isNotTimeout = SleepConditionVariableCS(&PRIVATE->nativeHandle, (PCRITICAL_SECTION)lk.handle(), timeoutMs) != 0;
|
||||||
#else
|
#else
|
||||||
timespec abstime = {.tv_sec = timeoutMs / 1000, .tv_nsec = timeoutMs * 1000 * 1000};
|
timespec abstime = {.tv_sec = timeoutMs / 1000, .tv_nsec = timeoutMs % 1000000 * 1000000};
|
||||||
isNotTimeout = pthread_cond_timedwait(&PRIVATE->nativeHandle, (pthread_mutex_t*)lk.handle(), &abstime) == 0;
|
isNotTimeout = pthread_cond_timedwait(&PRIVATE->nativeHandle, (pthread_mutex_t*)lk.handle(), &abstime) == 0;
|
||||||
#endif
|
#endif
|
||||||
if (PRIVATE->isDestroying) return false;
|
if (PRIVATE->isDestroying) return false;
|
||||||
@@ -105,17 +105,16 @@ bool PIConditionVariable::waitFor(PIMutex& lk, int timeoutMs, const std::functio
|
|||||||
isCondition = condition();
|
isCondition = condition();
|
||||||
if (isCondition) break;
|
if (isCondition) break;
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
WINBOOL isTimeout = SleepConditionVariableCS(
|
bool isTimeout = SleepConditionVariableCS(
|
||||||
&PRIVATE->nativeHandle,
|
&PRIVATE->nativeHandle,
|
||||||
(PCRITICAL_SECTION)lk.handle(),
|
(PCRITICAL_SECTION)lk.handle(),
|
||||||
timeoutMs - (int)measurer.elapsed_m());
|
timeoutMs - (int)measurer.elapsed_m()) == 0;
|
||||||
if (isTimeout == 0) return false;
|
|
||||||
#else
|
#else
|
||||||
int timeoutCurr = timeoutMs - (int)measurer.elapsed_m();
|
int timeoutCurr = timeoutMs - (int)measurer.elapsed_m();
|
||||||
timespec abstime = {.tv_sec = timeoutCurr / 1000, .tv_nsec = timeoutCurr * 1000 * 1000};
|
timespec abstime = {.tv_sec = timeoutCurr / 1000, .tv_nsec = timeoutCurr % 1000000 * 1000000};
|
||||||
bool isTimeout = pthread_cond_timedwait(&PRIVATE->nativeHandle, (pthread_mutex_t*)lk.handle(), &abstime) == 0;
|
bool isTimeout = pthread_cond_timedwait(&PRIVATE->nativeHandle, (pthread_mutex_t*)lk.handle(), &abstime) != 0;
|
||||||
if (isTimeout) return false;
|
|
||||||
#endif
|
#endif
|
||||||
|
if (isTimeout) return false;
|
||||||
if (PRIVATE->isDestroying) return false;
|
if (PRIVATE->isDestroying) return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user