/*
- * Copyright 2017 Facebook, Inc.
+ * Copyright 2015-present Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <atomic>
#include <cinttypes>
#include <cstdlib>
-#include <folly/Portability.h>
#include <mutex>
#include <type_traits>
-#include <folly/detail/Sleeper.h>
#include <glog/logging.h>
-#if !FOLLY_X64 && !FOLLY_A64 && !FOLLY_PPC64
-# error "PicoSpinLock.h is currently x64, aarch64 and ppc64 only."
+#include <folly/Portability.h>
+#include <folly/synchronization/detail/Sleeper.h>
+
+#if !FOLLY_X64 && !FOLLY_AARCH64 && !FOLLY_PPC64
+#error "PicoSpinLock.h is currently x64, aarch64 and ppc64 only."
#endif
namespace folly {
* have a real constructor because we want this to be a POD type so we
* can put it into packed structs.
*/
-template<class IntType, int Bit = sizeof(IntType) * 8 - 1>
+template <class IntType, int Bit = sizeof(IntType) * 8 - 1>
struct PicoSpinLock {
// Internally we deal with the unsigned version of the type.
typedef typename std::make_unsigned<IntType>::type UIntType;
}
#undef FB_DOBTS
-#elif FOLLY_A64
- ret =
- !(__atomic_fetch_or(&lock_, kLockBitMask_, __ATOMIC_SEQ_CST) &
- kLockBitMask_);
+#elif FOLLY_AARCH64
+ using SIntType = typename std::make_signed<UIntType>::type;
+ auto const lock = reinterpret_cast<SIntType*>(&lock_);
+ auto const mask = static_cast<SIntType>(kLockBitMask_);
+ return !(mask & __atomic_fetch_or(lock, mask, __ATOMIC_ACQUIRE));
#elif FOLLY_PPC64
#define FB_DOBTS(size) \
asm volatile("\teieio\n" \
}
#undef FB_DOBTR
-#elif FOLLY_A64
- __atomic_fetch_and(&lock_, ~kLockBitMask_, __ATOMIC_SEQ_CST);
+#elif FOLLY_AARCH64
+ using SIntType = typename std::make_signed<UIntType>::type;
+ auto const lock = reinterpret_cast<SIntType*>(&lock_);
+ auto const mask = static_cast<SIntType>(kLockBitMask_);
+ __atomic_fetch_and(lock, ~mask, __ATOMIC_RELEASE);
#elif FOLLY_PPC64
#define FB_DOBTR(size) \
asm volatile("\teieio\n" \
}
};
-}
+} // namespace folly