Disable zerocopy if we're notified about deferred copies, add a isZeroCopyWriteInProg...
[folly.git] / folly / PicoSpinLock.h
index 8ee98b848fb29b58fe5328c088e7f590a5fcc4b8..5c63583d451ea15a6110308b73900bf2635afe8e 100644 (file)
 #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/detail/Sleeper.h>
+
+#if !FOLLY_X64 && !FOLLY_AARCH64 && !FOLLY_PPC64
+#error "PicoSpinLock.h is currently x64, aarch64 and ppc64 only."
 #endif
 
 namespace folly {
@@ -68,7 +69,7 @@ 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;
@@ -170,8 +171,10 @@ struct PicoSpinLock {
     }
 
 #undef FB_DOBTS
-#elif FOLLY_A64
-    ret = __atomic_fetch_or(&lock_, 1 << Bit, __ATOMIC_SEQ_CST);
+#elif FOLLY_AARCH64
+    ret =
+        !(__atomic_fetch_or(&lock_, kLockBitMask_, __ATOMIC_SEQ_CST) &
+          kLockBitMask_);
 #elif FOLLY_PPC64
 #define FB_DOBTS(size)                                 \
     asm volatile("\teieio\n"                           \
@@ -251,8 +254,8 @@ struct PicoSpinLock {
     }
 
 #undef FB_DOBTR
-#elif FOLLY_A64
-    __atomic_fetch_and(&lock_, ~(1 << Bit), __ATOMIC_SEQ_CST);
+#elif FOLLY_AARCH64
+    __atomic_fetch_and(&lock_, ~kLockBitMask_, __ATOMIC_SEQ_CST);
 #elif FOLLY_PPC64
 #define FB_DOBTR(size)                                 \
     asm volatile("\teieio\n"                           \
@@ -281,4 +284,4 @@ struct PicoSpinLock {
   }
 };
 
-}
+} // namespace folly