From: Ben Hamilton Date: Wed, 1 Jun 2016 17:43:50 +0000 (-0700) Subject: Fix test/SynchronizedTest.cpp build break on Clang on OS X X-Git-Tag: 2016.07.26~172 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=70497e418f27ef544cf2cb47e56244e26c6e5e90;p=folly.git 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 --- diff --git a/folly/test/SynchronizedTest.cpp b/folly/test/SynchronizedTest.cpp index e0640f3d..dd97d28c 100644 --- a/folly/test/SynchronizedTest.cpp +++ b/folly/test/SynchronizedTest.cpp @@ -18,6 +18,7 @@ // Test bed for folly/Synchronized.h +#include #include #include #include @@ -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