diff options
author | Derek Mauro <dmauro@google.com> | 2023-02-16 11:52:26 -0800 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2023-02-16 11:53:15 -0800 |
commit | 0372af19f2f4f588351ca8f71b3f528cbe467a4d (patch) | |
tree | 80648200c70f522bf96cd9d0e90f55d1a2f489dc /absl/synchronization/internal/kernel_timeout.h | |
parent | 2d4c6872da56fa0d8156b01ab5658348d9c5de4d (diff) | |
download | abseil-0372af19f2f4f588351ca8f71b3f528cbe467a4d.tar.gz abseil-0372af19f2f4f588351ca8f71b3f528cbe467a4d.tar.bz2 abseil-0372af19f2f4f588351ca8f71b3f528cbe467a4d.zip |
Add KernelTimeout methods that convert the timeout to the
std::chrono methods used by std::condition_variable.
A followup change will add an implemention of
synchronization_internal::Waiter that can use
std:mutex/std::condition_variable to implement the per-thread
semaphore that absl::Mutex waits on. This implementation may at some
point become the default on platforms such as Windows where there
doesn't seem to be an easy way of supporting real absolute timeouts. In
this case we can defer to their standard library to implement correct
support.
PiperOrigin-RevId: 510204786
Change-Id: Icf4d695013fd060abbd53dae23e71ea36f731565
Diffstat (limited to 'absl/synchronization/internal/kernel_timeout.h')
-rw-r--r-- | absl/synchronization/internal/kernel_timeout.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/absl/synchronization/internal/kernel_timeout.h b/absl/synchronization/internal/kernel_timeout.h index 1f4d82cd..f7c40337 100644 --- a/absl/synchronization/internal/kernel_timeout.h +++ b/absl/synchronization/internal/kernel_timeout.h @@ -16,6 +16,7 @@ #define ABSL_SYNCHRONIZATION_INTERNAL_KERNEL_TIMEOUT_H_ #include <algorithm> +#include <chrono> // NOLINT(build/c++11) #include <cstdint> #include <ctime> #include <limits> @@ -95,6 +96,20 @@ class KernelTimeout { typedef unsigned long DWord; // NOLINT DWord InMillisecondsFromNow() const; + // Convert to std::chrono::time_point for interfaces that expect an absolute + // timeout, like std::condition_variable::wait_until(). If !has_timeout() or + // is_relative_timeout(), attempts to convert to a reasonable absolute + // timeout, but callers should test has_timeout() and is_relative_timeout() + // and prefer to use a more appropriate interface. + std::chrono::time_point<std::chrono::system_clock> ToChronoTimePoint() const; + + // Convert to std::chrono::time_point for interfaces that expect a relative + // timeout, like std::condition_variable::wait_for(). If !has_timeout() or + // is_absolute_timeout(), attempts to convert to a reasonable relative + // timeout, but callers should test has_timeout() and is_absolute_timeout() + // and prefer to use a more appropriate interface. + std::chrono::nanoseconds ToChronoDuration() const; + private: // Internal representation. // - If the value is kNoTimeout, then the timeout is infinite, and |