From e081efcade6da7cad61741a1d2f856bd7d686995 Mon Sep 17 00:00:00 2001 From: Michael Lee Date: Tue, 30 Aug 2016 19:29:59 -0700 Subject: [PATCH] Use a normal variable if thread local is not available. 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 | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/folly/SharedMutex.h b/folly/SharedMutex.h index b2a783d7..4ccdff2a 100644 --- a/folly/SharedMutex.h +++ b/folly/SharedMutex.h @@ -210,6 +210,17 @@ // 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 class Atom, bool BlockImmediately> -FOLLY_TLS uint32_t +FOLLY_SHAREDMUTEX_TLS uint32_t SharedMutexImpl:: tls_lastTokenlessSlot = 0; -- 2.34.1