#include <glog/logging.h>
#include <folly/Portability.h>
-#if !FOLLY_X64
-# error "SmallLocks.h is currently x64-only."
+#if !FOLLY_X64 && !FOLLY_A64
+# error "SmallLocks.h is currently x64 and aarch64 only."
#endif
namespace folly {
void wait() {
if (spinCount < kMaxActiveSpin) {
++spinCount;
- asm volatile("pause");
+ asm_volatile_pause();
} else {
/*
* Always sleep 0.5ms, assuming this will make the kernel put
bool try_lock() const {
bool ret = false;
+#if FOLLY_X64
#define FB_DOBTS(size) \
asm volatile("lock; bts" #size " %1, (%2); setnc %0" \
: "=r" (ret) \
}
#undef FB_DOBTS
+#elif FOLLY_A64
+ ret = __atomic_fetch_or(&lock_, 1 << Bit, __ATOMIC_SEQ_CST);
+#else
+#error "x86 aarch64 only"
+#endif
return ret;
}
* integer.
*/
void unlock() const {
+#if FOLLY_X64
#define FB_DOBTR(size) \
asm volatile("lock; btr" #size " %0, (%1)" \
: \
}
#undef FB_DOBTR
+#elif FOLLY_A64
+ __atomic_fetch_and(&lock_, ~(1 << Bit), __ATOMIC_SEQ_CST);
+#else
+# error "x64 aarch64 only"
+#endif
}
};