diff options
author | Derek Mauro <dmauro@google.com> | 2023-04-08 09:52:09 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2023-04-08 09:52:56 -0700 |
commit | 1a72ea7bb8ba27679dd8b179a4671d7d9b099d4b (patch) | |
tree | f1e4c715e0e99bbe4206fd91c5b207bb297be4f5 /absl/synchronization/internal/pthread_waiter.cc | |
parent | 42a3c030c958e6e099162b746ada04792b3a1c67 (diff) | |
download | abseil-1a72ea7bb8ba27679dd8b179a4671d7d9b099d4b.tar.gz abseil-1a72ea7bb8ba27679dd8b179a4671d7d9b099d4b.tar.bz2 abseil-1a72ea7bb8ba27679dd8b179a4671d7d9b099d4b.zip |
Synchronization: Support true relative timeouts using the POSIX
proposed standard pthread_cond_clockwait() and sem_clockwait().
These are currently implemented in glibc >= 2.30.
These methods take a clock and use an absolute time with reference
to that clock, so KernelTimeout now can produce these values.
PiperOrigin-RevId: 522824226
Change-Id: Ife98713f6f95d800b1f8e52d5364a3dbebc4f8a6
Diffstat (limited to 'absl/synchronization/internal/pthread_waiter.cc')
-rw-r--r-- | absl/synchronization/internal/pthread_waiter.cc | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/absl/synchronization/internal/pthread_waiter.cc b/absl/synchronization/internal/pthread_waiter.cc index a8dafd94..8d90cc45 100644 --- a/absl/synchronization/internal/pthread_waiter.cc +++ b/absl/synchronization/internal/pthread_waiter.cc @@ -78,6 +78,11 @@ PthreadWaiter::PthreadWaiter() : waiter_count_(0), wakeup_count_(0) { #define ABSL_INTERNAL_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP 1 #endif +#if defined(__GLIBC__) && \ + (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 30)) +#define ABSL_INTERNAL_HAVE_PTHREAD_COND_CLOCKWAIT 1 +#endif + // Calls pthread_cond_timedwait() or possibly something else like // pthread_cond_timedwait_relative_np() depending on the platform and // KernelTimeout requested. The return value is the same as the return @@ -94,6 +99,11 @@ int PthreadWaiter::TimedWait(KernelTimeout t) { #ifdef ABSL_INTERNAL_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP const auto rel_timeout = t.MakeRelativeTimespec(); return pthread_cond_timedwait_relative_np(&cv_, &mu_, &rel_timeout); +#elif defined(ABSL_INTERNAL_HAVE_PTHREAD_COND_CLOCKWAIT) && \ + defined(CLOCK_MONOTONIC) + const auto abs_clock_timeout = t.MakeClockAbsoluteTimespec(CLOCK_MONOTONIC); + return pthread_cond_clockwait(&cv_, &mu_, CLOCK_MONOTONIC, + &abs_clock_timeout); #endif } |