Skip to content

Commit

Permalink
issue-693: enable futex usage on arm
Browse files Browse the repository at this point in the history
This patch was contributed by user spotrh.
  • Loading branch information
Aliaksey Kandratsenka committed Jun 28, 2015
1 parent cb998e5 commit 7df7f14
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
1 change: 0 additions & 1 deletion src/base/linux_syscall_support.h
Expand Up @@ -83,7 +83,6 @@
* sys_fcntl(
* sys_fstat(
* sys_futex(
* sys_futex1(
* sys_getcpu(
* sys_getdents64(
* sys_getppid(
Expand Down
15 changes: 6 additions & 9 deletions src/base/spinlock_linux-inl.h
Expand Up @@ -51,15 +51,10 @@ static struct InitModule {
int x = 0;
// futexes are ints, so we can use them only when
// that's the same size as the lockword_ in SpinLock.
#ifdef __arm__
// ARM linux doesn't support sys_futex1(void*, int, int, struct timespec*);
have_futex = 0;
#else
have_futex = (sizeof (Atomic32) == sizeof (int) &&
sys_futex(&x, FUTEX_WAKE, 1, 0) >= 0);
#endif
sys_futex(&x, FUTEX_WAKE, 1, NULL, NULL, 0) >= 0);
if (have_futex &&
sys_futex(&x, FUTEX_WAKE | futex_private_flag, 1, 0) < 0) {
sys_futex(&x, FUTEX_WAKE | futex_private_flag, 1, NULL, NULL, 0) < 0) {
futex_private_flag = 0;
}
}
Expand All @@ -85,7 +80,8 @@ void SpinLockDelay(volatile Atomic32 *w, int32 value, int loop) {
tm.tv_nsec *= 16; // increase the delay; we expect explicit wakeups
sys_futex(reinterpret_cast<int *>(const_cast<Atomic32 *>(w)),
FUTEX_WAIT | futex_private_flag,
value, reinterpret_cast<struct kernel_timespec *>(&tm));
value, reinterpret_cast<struct kernel_timespec *>(&tm),
NULL, 0);
} else {
nanosleep(&tm, NULL);
}
Expand All @@ -96,7 +92,8 @@ void SpinLockDelay(volatile Atomic32 *w, int32 value, int loop) {
void SpinLockWake(volatile Atomic32 *w, bool all) {
if (have_futex) {
sys_futex(reinterpret_cast<int *>(const_cast<Atomic32 *>(w)),
FUTEX_WAKE | futex_private_flag, all? INT_MAX : 1, 0);
FUTEX_WAKE | futex_private_flag, all? INT_MAX : 1,
NULL, NULL, 0);
}
}

Expand Down

0 comments on commit 7df7f14

Please sign in to comment.