summaryrefslogtreecommitdiff
path: root/absl/synchronization/internal
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2022-12-15 16:09:01 -0800
committerGravatar Copybara-Service <copybara-worker@google.com>2022-12-15 16:09:55 -0800
commitd5240fc53307c536ef6b469cf6dbedeb304eba06 (patch)
treeebeaf9c28db051c5a3fad37d817c5ed609813687 /absl/synchronization/internal
parentd241d91992905a24efe0a0d4ca3561d592e54159 (diff)
Add MakeAbsNs to KernelTimeout.
Rather than add new friends every time a new (internal) use arises, just expose the timestamp. PiperOrigin-RevId: 495722262 Change-Id: I25d2ce64769dc58cbe634259f07c600ce6c1e714
Diffstat (limited to 'absl/synchronization/internal')
-rw-r--r--absl/synchronization/internal/kernel_timeout.h19
1 files changed, 17 insertions, 2 deletions
diff --git a/absl/synchronization/internal/kernel_timeout.h b/absl/synchronization/internal/kernel_timeout.h
index 44a3a2e8..020472a0 100644
--- a/absl/synchronization/internal/kernel_timeout.h
+++ b/absl/synchronization/internal/kernel_timeout.h
@@ -28,6 +28,7 @@
#include <time.h>
#include <algorithm>
+#include <cstdint>
#include <limits>
#include "absl/base/internal/raw_logging.h"
@@ -60,7 +61,10 @@ class KernelTimeout {
// Convert to parameter for sem_timedwait/futex/similar. Only for approved
// users. Do not call if !has_timeout.
- struct timespec MakeAbsTimespec();
+ struct timespec MakeAbsTimespec() const;
+
+ // Convert to unix epoch nanos. Do not call if !has_timeout.
+ int64_t MakeAbsNanos() const;
private:
// internal rep, not user visible: ns after unix epoch.
@@ -126,7 +130,7 @@ class KernelTimeout {
friend class Waiter;
};
-inline struct timespec KernelTimeout::MakeAbsTimespec() {
+inline struct timespec KernelTimeout::MakeAbsTimespec() const {
int64_t n = ns_;
static const int64_t kNanosPerSecond = 1000 * 1000 * 1000;
if (n == 0) {
@@ -150,6 +154,17 @@ inline struct timespec KernelTimeout::MakeAbsTimespec() {
return abstime;
}
+inline int64_t KernelTimeout::MakeAbsNanos() const {
+ if (ns_ == 0) {
+ ABSL_RAW_LOG(
+ ERROR, "Tried to create a timeout from a non-timeout; never do this.");
+ // But we'll try to continue sanely. no-timeout ~= saturated timeout.
+ return (std::numeric_limits<int64_t>::max)();
+ }
+
+ return ns_;
+}
+
} // namespace synchronization_internal
ABSL_NAMESPACE_END
} // namespace absl