Cleanup around linux futex, apply EINTR case for timed waits

Signed-off-by: falkTX <falktx@falktx.com>
This commit is contained in:
falkTX 2021-04-14 17:05:28 +01:00
parent 863b435e78
commit 365b7e3f05
No known key found for this signature in database
GPG Key ID: CDBAA37ABC74FBA0
1 changed files with 9 additions and 7 deletions

View File

@ -94,16 +94,16 @@ bool JackLinuxFutex::Wait()
fFutex->internal = !fFutex->internal;
}
const int wait_mode = fFutex->internal ? FUTEX_WAIT_PRIVATE : FUTEX_WAIT;
for (;;)
{
if (__sync_bool_compare_and_swap(&fFutex->futex, 1, 0))
return true;
if (::syscall(SYS_futex, fFutex, fFutex->internal ? FUTEX_WAIT_PRIVATE : FUTEX_WAIT, 0, NULL, NULL, 0) == 0)
continue;
if (errno != EAGAIN && errno != EINTR)
return false;
if (::syscall(SYS_futex, fFutex, wait_mode, 0, NULL, NULL, 0) != 0)
if (errno != EAGAIN && errno != EINTR)
return false;
}
}
@ -127,14 +127,16 @@ bool JackLinuxFutex::TimedWait(long usec)
const int nsecs = (usec % 1000000) * 1000;
const timespec timeout = { static_cast<time_t>(secs), nsecs };
const int wait_mode = fFutex->internal ? FUTEX_WAIT_PRIVATE : FUTEX_WAIT;
for (;;)
{
if (__sync_bool_compare_and_swap(&fFutex->futex, 1, 0))
return true;
if (::syscall(SYS_futex, fFutex, fFutex->internal ? FUTEX_WAIT_PRIVATE : FUTEX_WAIT, 0, &timeout, NULL, 0) != 0 && errno != EWOULDBLOCK)
return false;
if (::syscall(SYS_futex, fFutex, wait_mode, 0, &timeout, NULL, 0) != 0)
if (errno != EAGAIN && errno != EINTR)
return false;
}
}