about summary refs log tree commit diff
path: root/absl/base/internal/thread_identity.cc
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2019-11-26T17·00-0800
committerGennadiy Rozental <rogeeff@google.com>2019-11-26T17·37-0500
commit0514227d2547793b23e209809276375e41c76617 (patch)
treef2cfabd8a93bf4308eb62cad6e672d821bca0725 /absl/base/internal/thread_identity.cc
parent7f4fe64af80fe3c84db8ea938276c3690573c45e (diff)
Export of internal Abseil changes
--
2ba0e41a21fbdab36b2f4f3b0dd4b112bd788604 by Derek Mauro <dmauro@google.com>:

Remove the include of <intsafe.h>, which is missing on
some versions of MinGW. DWORD is easily replaced by uint32_t.

PiperOrigin-RevId: 282576177

--
238fd41114b3e83fcb91d2afe1e6dcce7cfd53b0 by Samuel Benzaquen <sbenza@google.com>:

Remove assertion in erase(iterator) that tries to use the comparator.
Add missing this-> qualifier.
Fix bug where node elements are not being destroyed properly.

PiperOrigin-RevId: 282427096

--
6b9446e3b38ed97451c010933e86a572ab659ab2 by Derek Mauro <dmauro@google.com>:

Improves/fixes feature detection in thread_identity

Only use ABSL_PER_THREAD_TLS_KEYWORD when it is supported (previously
on some platforms it evaluated to nothing, which completely breaks
everything), but prefer it to thread_local since benchmarks indicate
it is slightly faster in this critical code path.

Disable the calls to pthread_sigmask on MinGW where it is not
supported.

PiperOrigin-RevId: 282425291
GitOrigin-RevId: 2ba0e41a21fbdab36b2f4f3b0dd4b112bd788604
Change-Id: I34073ecbb4a43ad71f54161c136d88fc728888f1
Diffstat (limited to 'absl/base/internal/thread_identity.cc')
-rw-r--r--absl/base/internal/thread_identity.cc13
1 files changed, 9 insertions, 4 deletions
diff --git a/absl/base/internal/thread_identity.cc b/absl/base/internal/thread_identity.cc
index 91273a6b1a17..0ea159c58628 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.