aboutsummaryrefslogtreecommitdiffhomepage
path: root/absl/base
diff options
context:
space:
mode:
Diffstat (limited to 'absl/base')
-rw-r--r--absl/base/internal/sysinfo.cc2
-rw-r--r--absl/base/internal/sysinfo.h11
-rw-r--r--absl/base/internal/thread_identity.cc13
-rw-r--r--absl/base/internal/thread_identity.h9
4 files changed, 24 insertions, 11 deletions
diff --git a/absl/base/internal/sysinfo.cc b/absl/base/internal/sysinfo.cc
index 4dd3add..93039bf 100644
--- a/absl/base/internal/sysinfo.cc
+++ b/absl/base/internal/sysinfo.cc
@@ -277,7 +277,7 @@ double NominalCPUFrequency() {
#if defined(_WIN32)
pid_t GetTID() {
- return GetCurrentThreadId();
+ return pid_t{GetCurrentThreadId()};
}
#elif defined(__linux__)
diff --git a/absl/base/internal/sysinfo.h b/absl/base/internal/sysinfo.h
index b864a59..93356d8 100644
--- a/absl/base/internal/sysinfo.h
+++ b/absl/base/internal/sysinfo.h
@@ -26,10 +26,10 @@
#ifndef _WIN32
#include <sys/types.h>
-#else
-#include <intsafe.h>
#endif
+#include <cstdint>
+
#include "absl/base/port.h"
namespace absl {
@@ -51,9 +51,10 @@ int NumCPUs();
// On Linux, you may send a signal to the resulting ID with kill(). However,
// it is recommended for portability that you use pthread_kill() instead.
#ifdef _WIN32
-// On Windows, process id and thread id are of the same type according to
-// the return types of GetProcessId() and GetThreadId() are both DWORD.
-using pid_t = DWORD;
+// On Windows, process id and thread id are of the same type according to the
+// return types of GetProcessId() and GetThreadId() are both DWORD, an unsigned
+// 32-bit type.
+using pid_t = uint32_t;
#endif
pid_t GetTID();
diff --git a/absl/base/internal/thread_identity.cc b/absl/base/internal/thread_identity.cc
index 91273a6..0ea159c 100644
--- a/absl/base/internal/thread_identity.cc
+++ b/absl/base/internal/thread_identity.cc
@@ -55,7 +55,12 @@ void AllocateThreadIdentityKey(ThreadIdentityReclaimerFunction reclaimer) {
#ifdef __GNUC__
__attribute__((visibility("protected")))
#endif // __GNUC__
- ABSL_PER_THREAD_TLS_KEYWORD ThreadIdentity* thread_identity_ptr;
+#if ABSL_PER_THREAD_TLS
+// Prefer __thread to thread_local as benchmarks indicate it is a bit faster.
+ABSL_PER_THREAD_TLS_KEYWORD ThreadIdentity* thread_identity_ptr = nullptr;
+#elif defined(ABSL_HAVE_THREAD_LOCAL)
+thread_local ThreadIdentity* thread_identity_ptr = nullptr;
+#endif // ABSL_PER_THREAD_TLS
#endif // TLS or CPP11
void SetCurrentThreadIdentity(
@@ -69,8 +74,8 @@ void SetCurrentThreadIdentity(
absl::call_once(init_thread_identity_key_once, AllocateThreadIdentityKey,
reclaimer);
-#ifdef __EMSCRIPTEN__
- // Emscripten PThread implementation does not support signals.
+#if defined(__EMSCRIPTEN__) || defined(__MINGW32__)
+ // Emscripten and MinGW pthread implementations does not support signals.
// See https://kripken.github.io/emscripten-site/docs/porting/pthreads.html
// for more information.
pthread_setspecific(thread_identity_pthread_key,
@@ -89,7 +94,7 @@ void SetCurrentThreadIdentity(
pthread_setspecific(thread_identity_pthread_key,
reinterpret_cast<void*>(identity));
pthread_sigmask(SIG_SETMASK, &curr_signals, nullptr);
-#endif // !__EMSCRIPTEN__
+#endif // !__EMSCRIPTEN__ && !__MINGW32__
#elif ABSL_THREAD_IDENTITY_MODE == ABSL_THREAD_IDENTITY_MODE_USE_TLS
// NOTE: Not async-safe. But can be open-coded.
diff --git a/absl/base/internal/thread_identity.h b/absl/base/internal/thread_identity.h
index b34674a..7cbce9c 100644
--- a/absl/base/internal/thread_identity.h
+++ b/absl/base/internal/thread_identity.h
@@ -224,7 +224,14 @@ void ClearCurrentThreadIdentity();
#if ABSL_THREAD_IDENTITY_MODE == ABSL_THREAD_IDENTITY_MODE_USE_TLS || \
ABSL_THREAD_IDENTITY_MODE == ABSL_THREAD_IDENTITY_MODE_USE_CPP11
-extern ABSL_PER_THREAD_TLS_KEYWORD ThreadIdentity* thread_identity_ptr;
+#if ABSL_PER_THREAD_TLS
+ABSL_CONST_INIT extern ABSL_PER_THREAD_TLS_KEYWORD ThreadIdentity*
+ thread_identity_ptr;
+#elif defined(ABSL_HAVE_THREAD_LOCAL)
+ABSL_CONST_INIT extern thread_local ThreadIdentity* thread_identity_ptr;
+#else
+#error Thread-local storage not detected on this platform
+#endif
inline ThreadIdentity* CurrentThreadIdentityIfPresent() {
return thread_identity_ptr;