[common] linux: fix issue with infinite timeout events

This commit is contained in:
Geoffrey McRae 2020-08-11 19:31:11 +10:00
parent 380b5df9f9
commit 431ae3fc55
2 changed files with 9 additions and 5 deletions

View File

@ -1 +1 @@
B2-rc3-13-g76e119f8ad+1
B2-rc3-21-g380b5df9f9+1

View File

@ -83,19 +83,20 @@ bool lgWaitEventAbs(LGEvent * handle, struct timespec * ts)
}
bool ret = true;
int res;
while(ret && !atomic_load(&handle->flag))
{
if (!ts)
{
if (pthread_cond_wait(&handle->cond, &handle->mutex) != 0)
if ((res = pthread_cond_wait(&handle->cond, &handle->mutex)) != 0)
{
DEBUG_ERROR("Wait to wait on the condition");
DEBUG_ERROR("Failed to wait on the condition (err: %d)", res);
ret = false;
}
}
else
{
switch(pthread_cond_timedwait(&handle->cond, &handle->mutex, ts))
switch((res = pthread_cond_timedwait(&handle->cond, &handle->mutex, ts)))
{
case 0:
break;
@ -106,7 +107,7 @@ bool lgWaitEventAbs(LGEvent * handle, struct timespec * ts)
default:
ret = false;
DEBUG_ERROR("Timed wait failed");
DEBUG_ERROR("Timed wait failed (err: %d)", res);
break;
}
}
@ -145,6 +146,9 @@ bool lgWaitEventNS(LGEvent * handle, unsigned int timeout)
bool lgWaitEvent(LGEvent * handle, unsigned int timeout)
{
if (timeout == TIMEOUT_INFINITE)
return lgWaitEventAbs(handle, NULL);
return lgWaitEventNS(handle, timeout * 1000000);
}