Browse Source

Cleanup around linux futex, apply EINTR case for timed waits

Signed-off-by: falkTX <falktx@falktx.com>
tags/v1.9.18^2
falkTX 5 months ago
parent
commit
365b7e3f05
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
1 changed files with 9 additions and 7 deletions
  1. +9
    -7
      linux/JackLinuxFutex.cpp

+ 9
- 7
linux/JackLinuxFutex.cpp 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;
}
}



Loading…
Cancel
Save