Commit b1eb6819 authored by Michael Lee's avatar Michael Lee Committed by Facebook Github Bot 5

Adding portability to gating PicoSpinLock.

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
parent 321359e0
......@@ -31,6 +31,7 @@
*/
#pragma once
#define FOLLY_PICO_SPIN_LOCK_H_
/*
* @author Keith Adams <kma@fb.com>
......@@ -38,16 +39,16 @@
*/
#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."
......
......@@ -36,6 +36,10 @@
#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
......@@ -34,9 +34,12 @@
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();
......
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