| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| #include <linux/futex.h> |
| #include <sys/syscall.h> |
| #include <unistd.h> |
|
|
| #include <atomic> |
| #include <climits> |
| #include <cstdint> |
| #include <ctime> |
|
|
| #include "absl/base/attributes.h" |
| #include "absl/base/internal/errno_saver.h" |
|
|
| |
| |
| |
| |
| |
| |
| static_assert(sizeof(std::atomic<uint32_t>) == sizeof(int), |
| "SpinLock lockword has the wrong size for a futex"); |
|
|
| |
| |
| #ifdef __BIONIC__ |
| #ifndef SYS_futex |
| #define SYS_futex __NR_futex |
| #endif |
| #ifndef FUTEX_PRIVATE_FLAG |
| #define FUTEX_PRIVATE_FLAG 128 |
| #endif |
| #endif |
|
|
| #if defined(__NR_futex_time64) && !defined(SYS_futex_time64) |
| #define SYS_futex_time64 __NR_futex_time64 |
| #endif |
|
|
| #if defined(SYS_futex_time64) && !defined(SYS_futex) |
| #define SYS_futex SYS_futex_time64 |
| #endif |
|
|
| extern "C" { |
|
|
| ABSL_ATTRIBUTE_WEAK void ABSL_INTERNAL_C_SYMBOL(AbslInternalSpinLockDelay)( |
| std::atomic<uint32_t> *w, uint32_t value, int, |
| absl::base_internal::SchedulingMode) { |
| absl::base_internal::ErrnoSaver errno_saver; |
| syscall(SYS_futex, w, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, value, nullptr); |
| } |
|
|
| ABSL_ATTRIBUTE_WEAK void ABSL_INTERNAL_C_SYMBOL(AbslInternalSpinLockWake)( |
| std::atomic<uint32_t> *w, bool all) { |
| syscall(SYS_futex, w, FUTEX_WAKE | FUTEX_PRIVATE_FLAG, all ? INT_MAX : 1, 0); |
| } |
|
|
| } |
|
|