Use a normal variable if thread local is not available.
authorMichael Lee <mzlee@fb.com>
Wed, 31 Aug 2016 02:29:59 +0000 (19:29 -0700)
committerFacebook Github Bot 4 <facebook-github-bot-4-bot@fb.com>
Wed, 31 Aug 2016 02:38:43 +0000 (19:38 -0700)
Summary: This should not affect correctness, but it means SharedMutex would need to share the variable across threads.

Reviewed By: yfeldblum

Differential Revision: D3621227

fbshipit-source-id: dc1baa7c47cd2d459cd0ef89451bcd7fd4d553aa

folly/SharedMutex.h

index b2a783d7a23aeddf26da70e765f1a207f0a7a32a..4ccdff2a0a07162b711a67a806533bc1ee6aef52 100644 (file)
 // in all but the most extreme cases.  Make sure to check that the
 // increased icache and dcache footprint of the tagged result is worth it.
 
+// SharedMutex's use of thread local storage is as an optimization, so
+// for the case where thread local storage is not supported, define it
+// away.
+#ifndef FOLLY_SHAREDMUTEX_TLS
+#if !FOLLY_MOBILE
+#define FOLLY_SHAREDMUTEX_TLS FOLLY_TLS
+#else
+#define FOLLY_SHAREDMUTEX_TLS
+#endif
+#endif
+
 namespace folly {
 
 struct SharedMutexToken {
@@ -710,7 +721,7 @@ class SharedMutexImpl {
   static constexpr uintptr_t kTokenless = 0x1;
 
   // This is the starting location for Token-less unlock_shared().
-  static FOLLY_TLS uint32_t tls_lastTokenlessSlot;
+  static FOLLY_SHAREDMUTEX_TLS uint32_t tls_lastTokenlessSlot;
 
   // Only indexes divisible by kDeferredSeparationFactor are used.
   // If any of those elements points to a SharedMutexImpl, then it
@@ -1328,7 +1339,7 @@ template <
     typename Tag_,
     template <typename> class Atom,
     bool BlockImmediately>
-FOLLY_TLS uint32_t
+FOLLY_SHAREDMUTEX_TLS uint32_t
     SharedMutexImpl<ReaderPriority, Tag_, Atom, BlockImmediately>::
         tls_lastTokenlessSlot = 0;