Commit 70497e41 authored by Ben Hamilton's avatar Ben Hamilton Committed by Facebook Github Bot 5

Fix test/SynchronizedTest.cpp build break on Clang on OS X

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
parent 3fe4dacd
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
// Test bed for folly/Synchronized.h // Test bed for folly/Synchronized.h
#include <folly/Portability.h>
#include <folly/Synchronized.h> #include <folly/Synchronized.h>
#include <folly/RWSpinLock.h> #include <folly/RWSpinLock.h>
#include <folly/SharedMutex.h> #include <folly/SharedMutex.h>
...@@ -34,13 +35,13 @@ using SynchronizedTestTypes = testing::Types ...@@ -34,13 +35,13 @@ using SynchronizedTestTypes = testing::Types
, folly::SharedMutexWritePriority , folly::SharedMutexWritePriority
, std::mutex , std::mutex
, std::recursive_mutex , std::recursive_mutex
#ifdef FOLLY_SYNCHRONIZED_HAVE_TIMED_MUTEXES #if FOLLY_SYNCHRONIZED_HAVE_TIMED_MUTEXES
, std::timed_mutex , std::timed_mutex
, std::recursive_timed_mutex , std::recursive_timed_mutex
#endif #endif
, boost::mutex , boost::mutex
, boost::recursive_mutex , boost::recursive_mutex
#ifdef FOLLY_SYNCHRONIZED_HAVE_TIMED_MUTEXES #if FOLLY_SYNCHRONIZED_HAVE_TIMED_MUTEXES
, boost::timed_mutex , boost::timed_mutex
, boost::recursive_timed_mutex , boost::recursive_timed_mutex
#endif #endif
...@@ -78,7 +79,7 @@ class SynchronizedTimedTest : public testing::Test {}; ...@@ -78,7 +79,7 @@ class SynchronizedTimedTest : public testing::Test {};
using SynchronizedTimedTestTypes = testing::Types using SynchronizedTimedTestTypes = testing::Types
< folly::SharedMutexReadPriority < folly::SharedMutexReadPriority
, folly::SharedMutexWritePriority , folly::SharedMutexWritePriority
#ifdef FOLLY_SYNCHRONIZED_HAVE_TIMED_MUTEXES #if FOLLY_SYNCHRONIZED_HAVE_TIMED_MUTEXES
, std::timed_mutex , std::timed_mutex
, std::recursive_timed_mutex , std::recursive_timed_mutex
, boost::timed_mutex , boost::timed_mutex
...@@ -102,7 +103,7 @@ class SynchronizedTimedWithConstTest : public testing::Test {}; ...@@ -102,7 +103,7 @@ class SynchronizedTimedWithConstTest : public testing::Test {};
using SynchronizedTimedWithConstTestTypes = testing::Types using SynchronizedTimedWithConstTestTypes = testing::Types
< folly::SharedMutexReadPriority < folly::SharedMutexReadPriority
, folly::SharedMutexWritePriority , folly::SharedMutexWritePriority
#ifdef FOLLY_SYNCHRONIZED_HAVE_TIMED_MUTEXES #if FOLLY_SYNCHRONIZED_HAVE_TIMED_MUTEXES
, boost::shared_mutex , boost::shared_mutex
#endif #endif
#ifdef RW_SPINLOCK_USE_X86_INTRINSIC_ #ifdef RW_SPINLOCK_USE_X86_INTRINSIC_
...@@ -147,15 +148,15 @@ class FakeMutex { ...@@ -147,15 +148,15 @@ class FakeMutex {
// Keep these two static for test access // Keep these two static for test access
// Keep them thread_local in case of tests are run in parallel within one // Keep them thread_local in case of tests are run in parallel within one
// process // process
static thread_local int lockCount_; static FOLLY_TLS int lockCount_;
static thread_local int unlockCount_; static FOLLY_TLS int unlockCount_;
// Adapters for Synchronized<> // Adapters for Synchronized<>
friend void acquireReadWrite(FakeMutex& lock) { lock.lock(); } friend void acquireReadWrite(FakeMutex& lock) { lock.lock(); }
friend void releaseReadWrite(FakeMutex& lock) { lock.unlock(); } friend void releaseReadWrite(FakeMutex& lock) { lock.unlock(); }
}; };
thread_local int FakeMutex::lockCount_{0}; FOLLY_TLS int FakeMutex::lockCount_{0};
thread_local int FakeMutex::unlockCount_{0}; FOLLY_TLS int FakeMutex::unlockCount_{0};
// SynchronizedLockTest is used to verify the correct lock unlock behavior // SynchronizedLockTest is used to verify the correct lock unlock behavior
// happens per design // happens per design
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment