Adding portability to gating PicoSpinLock.
authorMichael Lee <mzlee@fb.com>
Fri, 11 Mar 2016 00:50:53 +0000 (16:50 -0800)
committerFacebook Github Bot 5 <facebook-github-bot-5-bot@fb.com>
Fri, 11 Mar 2016 01:05:20 +0000 (17:05 -0800)
Summary:PicoSpinLock only works on x86_64, Arm64, and ppc64 (i.e.,
not 32-bit).  Add a bit of gating so we can continue to run tests and
use headers when compiling for i386.

Reviewed By: yfeldblum

Differential Revision: D2991328

fb-gh-sync-id: b0d0c229508f65dff62b24fdd9d80c799cd97935
shipit-source-id: b0d0c229508f65dff62b24fdd9d80c799cd97935

folly/PicoSpinLock.h
folly/SmallLocks.h
folly/test/SmallLocksTest.cpp

index 19472b31fd0d86e913114f03e71fa05777e011f4..32c5abfb43ae742895a27cde78f9fa802c1eb572 100644 (file)
@@ -31,6 +31,7 @@
  */
 
 #pragma once
+#define FOLLY_PICO_SPIN_LOCK_H_
 
 /*
  * @author Keith Adams <kma@fb.com>
  */
 
 #include <array>
+#include <atomic>
 #include <cinttypes>
-#include <type_traits>
 #include <cstdlib>
-#include <pthread.h>
+#include <folly/Portability.h>
 #include <mutex>
-#include <atomic>
+#include <pthread.h>
+#include <type_traits>
 
 #include <glog/logging.h>
 #include <folly/detail/Sleeper.h>
-#include <folly/Portability.h>
 
 #if !FOLLY_X64 && !FOLLY_A64 && !FOLLY_PPC64
 # error "PicoSpinLock.h is currently x64, aarch64 and ppc64 only."
index b73932b78a094a31bd538ec02dda2a1a7247755c..88fefe3e966d772d58174f1571769b8d31999c08 100644 (file)
 
 #include <folly/MicroLock.h>
 #include <folly/MicroSpinLock.h>
+
+#include <folly/Portability.h>
+#if FOLLY_X64 || FOLLY_A64 || FOLLY_PPC64
 #include <folly/PicoSpinLock.h>
+#endif
 
 #endif
index d7e27578adca527c95806406b6cf09083916664a..f33e023166a729281e61faf92cc381da85ea5778 100644 (file)
 using folly::MSLGuard;
 using folly::MicroLock;
 using folly::MicroSpinLock;
-using folly::PicoSpinLock;
 using std::string;
 
+#ifdef FOLLY_PICO_SPIN_LOCK_H_
+using folly::PicoSpinLock;
+#endif
+
 namespace {
 
 struct LockedVal {
@@ -53,10 +56,12 @@ struct LockedVal {
 // these classes are POD).
 FOLLY_PACK_PUSH
 struct ignore1 { MicroSpinLock msl; int16_t foo; } FOLLY_PACK_ATTR;
-struct ignore2 { PicoSpinLock<uint32_t> psl; int16_t foo; } FOLLY_PACK_ATTR;
 static_assert(sizeof(ignore1) == 3, "Size check failed");
-static_assert(sizeof(ignore2) == 6, "Size check failed");
 static_assert(sizeof(MicroSpinLock) == 1, "Size check failed");
+#ifdef FOLLY_PICO_SPIN_LOCK_H_
+struct ignore2 { PicoSpinLock<uint32_t> psl; int16_t foo; } FOLLY_PACK_ATTR;
+static_assert(sizeof(ignore2) == 6, "Size check failed");
+#endif
 FOLLY_PACK_POP
 
 LockedVal v;
@@ -78,6 +83,7 @@ void splock_test() {
   }
 }
 
+#ifdef FOLLY_PICO_SPIN_LOCK_H_
 template<class T> struct PslTest {
   PicoSpinLock<T> lock;
 
@@ -109,6 +115,7 @@ void doPslTest() {
     t.join();
   }
 }
+#endif
 
 struct TestClobber {
   TestClobber() {
@@ -141,6 +148,7 @@ TEST(SmallLocks, SpinLockCorrectness) {
   }
 }
 
+#ifdef FOLLY_PICO_SPIN_LOCK_H_
 TEST(SmallLocks, PicoSpinCorrectness) {
   doPslTest<int16_t>();
   doPslTest<uint16_t>();
@@ -164,6 +172,7 @@ TEST(SmallLocks, PicoSpinSigned) {
   }
   EXPECT_EQ(val.getData(), -8);
 }
+#endif
 
 TEST(SmallLocks, RegClobber) {
   TestClobber().go();