Fix test/SynchronizedTest.cpp build break on Clang on OS X
authorBen Hamilton <beng@fb.com>
Wed, 1 Jun 2016 17:43:50 +0000 (10:43 -0700)
committerFacebook Github Bot 5 <facebook-github-bot-5-bot@fb.com>
Wed, 1 Jun 2016 17:53:27 +0000 (10:53 -0700)
Summary:
The Folly `make check` build is broken with Clang on OS X.

This diff fixes the following break in `test/SynchronizedTest.cpp`:

  SynchronizedTest.cpp:150:10: error: thread-local storage is not supported for the current target
    static thread_local int lockCount_;

The problem is clang on OS X doesn't support the `thread_local` extension:

http://stackoverflow.com/a/29929949

so we now use the `FOLLY_TLS` compatibility macro.

When I fixed this, I found the test also failed to compile if `FOLLY_SYNCHRONIZED_HAVE_TIMED_MUTEXES` was `#define`d to `0` (as it is on OS X), so I fixed that.

Reviewed By: mzlee

Differential Revision: D3361215

fbshipit-source-id: e93be6872bcab03090448b9421e502e472f149ff

folly/test/SynchronizedTest.cpp

index e0640f3d6fbe1044c2c9875cb16c5cdba0ba1684..dd97d28cbdfb7250bd473486477a586ef80bd4f0 100644 (file)
@@ -18,6 +18,7 @@
 
 // Test bed for folly/Synchronized.h
 
+#include <folly/Portability.h>
 #include <folly/Synchronized.h>
 #include <folly/RWSpinLock.h>
 #include <folly/SharedMutex.h>
@@ -34,13 +35,13 @@ using SynchronizedTestTypes = testing::Types
   , folly::SharedMutexWritePriority
   , std::mutex
   , std::recursive_mutex
-#ifdef FOLLY_SYNCHRONIZED_HAVE_TIMED_MUTEXES
+#if FOLLY_SYNCHRONIZED_HAVE_TIMED_MUTEXES
   , std::timed_mutex
   , std::recursive_timed_mutex
 #endif
   , boost::mutex
   , boost::recursive_mutex
-#ifdef FOLLY_SYNCHRONIZED_HAVE_TIMED_MUTEXES
+#if FOLLY_SYNCHRONIZED_HAVE_TIMED_MUTEXES
   , boost::timed_mutex
   , boost::recursive_timed_mutex
 #endif
@@ -78,7 +79,7 @@ class SynchronizedTimedTest : public testing::Test {};
 using SynchronizedTimedTestTypes = testing::Types
   < folly::SharedMutexReadPriority
   , folly::SharedMutexWritePriority
-#ifdef FOLLY_SYNCHRONIZED_HAVE_TIMED_MUTEXES
+#if FOLLY_SYNCHRONIZED_HAVE_TIMED_MUTEXES
   , std::timed_mutex
   , std::recursive_timed_mutex
   , boost::timed_mutex
@@ -102,7 +103,7 @@ class SynchronizedTimedWithConstTest : public testing::Test {};
 using SynchronizedTimedWithConstTestTypes = testing::Types
   < folly::SharedMutexReadPriority
   , folly::SharedMutexWritePriority
-#ifdef FOLLY_SYNCHRONIZED_HAVE_TIMED_MUTEXES
+#if FOLLY_SYNCHRONIZED_HAVE_TIMED_MUTEXES
   , boost::shared_mutex
 #endif
 #ifdef RW_SPINLOCK_USE_X86_INTRINSIC_
@@ -147,15 +148,15 @@ class FakeMutex {
   // Keep these two static for test access
   // Keep them thread_local in case of tests are run in parallel within one
   // process
-  static thread_local int lockCount_;
-  static thread_local int unlockCount_;
+  static FOLLY_TLS int lockCount_;
+  static FOLLY_TLS int unlockCount_;
 
   // Adapters for Synchronized<>
   friend void acquireReadWrite(FakeMutex& lock) { lock.lock(); }
   friend void releaseReadWrite(FakeMutex& lock) { lock.unlock(); }
 };
-thread_local int FakeMutex::lockCount_{0};
-thread_local int FakeMutex::unlockCount_{0};
+FOLLY_TLS int FakeMutex::lockCount_{0};
+FOLLY_TLS int FakeMutex::unlockCount_{0};
 
 // SynchronizedLockTest is used to verify the correct lock unlock behavior
 // happens per design