*/
#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."
#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
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 {
// 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;
}
}
+#ifdef FOLLY_PICO_SPIN_LOCK_H_
template<class T> struct PslTest {
PicoSpinLock<T> lock;
t.join();
}
}
+#endif
struct TestClobber {
TestClobber() {
}
}
+#ifdef FOLLY_PICO_SPIN_LOCK_H_
TEST(SmallLocks, PicoSpinCorrectness) {
doPslTest<int16_t>();
doPslTest<uint16_t>();
}
EXPECT_EQ(val.getData(), -8);
}
+#endif
TEST(SmallLocks, RegClobber) {
TestClobber().go();