summaryrefslogtreecommitdiff
path: root/absl/base/internal
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2020-07-24 13:00:52 -0700
committerGravatar Andy Getz <durandal@google.com>2020-07-24 16:15:46 -0400
commit2c8a5b0d890cfbd2c1e70163e347f3e00b4ddb49 (patch)
treed34982e21f00fdac3eaa2f049e2bc6113bed105b /absl/base/internal
parent41a6263fd0bcc93a90ff739785f17260f8ea061e (diff)
Export of internal Abseil changes
-- 873b52b0a691e759413c5db27dafc541a5da5263 by Andy Getzendanner <durandal@google.com>: Introduce an internal-only thread-local caching wrapper around GetTID. PiperOrigin-RevId: 323055682 -- 091a4537f1ef6e158acbf4261cfae1af7a3bdb7f by Abseil Team <absl-team@google.com>: Internal change PiperOrigin-RevId: 322864497 -- c80ccfff2a825819f31826a30f48cca3297699f8 by Evan Brown <ezb@google.com>: Roll forward b-tree changes simplifying deletion and getting rid of recursion in clear_and_delete(). We also change clear_and_delete() to avoid some unnecessary comparisons by restructuring the loops. PiperOrigin-RevId: 322658938 -- 81464c0fb9c8c6268dca2e530aba99e75e1e59ae by Gennadiy Rozental <rogeeff@google.com>: Eliminate definition of RunningOnValgrind inside the library. Fixes #674 Fixes #657 PiperOrigin-RevId: 322508440 GitOrigin-RevId: 873b52b0a691e759413c5db27dafc541a5da5263 Change-Id: I20b40c9e8fc62edcf981caab467cca33cf6fd2ba
Diffstat (limited to 'absl/base/internal')
-rw-r--r--absl/base/internal/sysinfo.cc14
-rw-r--r--absl/base/internal/sysinfo.h8
2 files changed, 22 insertions, 0 deletions
diff --git a/absl/base/internal/sysinfo.cc b/absl/base/internal/sysinfo.cc
index 6c69683f..349d9268 100644
--- a/absl/base/internal/sysinfo.cc
+++ b/absl/base/internal/sysinfo.cc
@@ -39,6 +39,7 @@
#endif
#include <string.h>
+
#include <cassert>
#include <cstdint>
#include <cstdio>
@@ -50,6 +51,7 @@
#include <vector>
#include "absl/base/call_once.h"
+#include "absl/base/config.h"
#include "absl/base/internal/raw_logging.h"
#include "absl/base/internal/spinlock.h"
#include "absl/base/internal/unscaledcycleclock.h"
@@ -420,6 +422,18 @@ pid_t GetTID() {
#endif
+// GetCachedTID() caches the thread ID in thread-local storage (which is a
+// userspace construct) to avoid unnecessary system calls. Without this caching,
+// it can take roughly 98ns, while it takes roughly 1ns with this caching.
+pid_t GetCachedTID() {
+#if ABSL_HAVE_THREAD_LOCAL
+ static thread_local pid_t thread_id = GetTID();
+ return thread_id;
+#else
+ return GetTID();
+#endif // ABSL_HAVE_THREAD_LOCAL
+}
+
} // namespace base_internal
ABSL_NAMESPACE_END
} // namespace absl
diff --git a/absl/base/internal/sysinfo.h b/absl/base/internal/sysinfo.h
index 7246d5dd..119cf1f0 100644
--- a/absl/base/internal/sysinfo.h
+++ b/absl/base/internal/sysinfo.h
@@ -30,6 +30,7 @@
#include <cstdint>
+#include "absl/base/config.h"
#include "absl/base/port.h"
namespace absl {
@@ -59,6 +60,13 @@ using pid_t = uint32_t;
#endif
pid_t GetTID();
+// Like GetTID(), but caches the result in thread-local storage in order
+// to avoid unnecessary system calls. Note that there are some cases where
+// one must call through to GetTID directly, which is why this exists as a
+// separate function. For example, GetCachedTID() is not safe to call in
+// an asynchronous signal-handling context nor right after a call to fork().
+pid_t GetCachedTID();
+
} // namespace base_internal
ABSL_NAMESPACE_END
} // namespace absl