summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfalkTX <falktx@falktx.com>2021-04-14 17:05:28 +0100
committerfalkTX <falktx@falktx.com>2021-04-14 17:05:28 +0100
commit365b7e3f05b01746fe5a39d83a3fa44b19e362c3 (patch)
tree7a9a5c9ff16e47238cfc56b01906682884fdb63b
parent863b435e785a8f6eec17754a4dd36cf818ed9e95 (diff)
downloadjack2-365b7e3f05b01746fe5a39d83a3fa44b19e362c3.tar.gz
Cleanup around linux futex, apply EINTR case for timed waits
Signed-off-by: falkTX <falktx@falktx.com>
-rw-r--r--linux/JackLinuxFutex.cpp16
1 files changed, 9 insertions, 7 deletions
diff --git a/linux/JackLinuxFutex.cpp b/linux/JackLinuxFutex.cpp
index 1dcab737..29b13901 100644
--- a/linux/JackLinuxFutex.cpp
+++ b/linux/JackLinuxFutex.cpp
@@ -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;
}
}