X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2FSmallLocks.h;h=0624e8a4fe0a1095c5b7638c7c19e6c3cdd4bf93;hb=6457c4429379011d12ee841e8325dddeebec538e;hp=6e7d68d1c73c5ba56e3cab3191874cffd30897e4;hpb=372fad515345d453e340a01b54b2ded98a6f2f40;p=folly.git diff --git a/folly/SmallLocks.h b/folly/SmallLocks.h index 6e7d68d1..0624e8a4 100644 --- a/folly/SmallLocks.h +++ b/folly/SmallLocks.h @@ -47,8 +47,8 @@ #include #include -#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 { @@ -72,7 +72,7 @@ namespace detail { void wait() { if (spinCount < kMaxActiveSpin) { ++spinCount; - asm volatile("pause"); + asm_volatile_pause(); } else { /* * Always sleep 0.5ms, assuming this will make the kernel put @@ -217,6 +217,7 @@ struct PicoSpinLock { 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) \ @@ -231,6 +232,11 @@ struct PicoSpinLock { } #undef FB_DOBTS +#elif FOLLY_A64 + ret = __atomic_fetch_or(&lock_, 1 << Bit, __ATOMIC_SEQ_CST); +#else +#error "x86 aarch64 only" +#endif return ret; } @@ -250,6 +256,7 @@ struct PicoSpinLock { * integer. */ void unlock() const { +#if FOLLY_X64 #define FB_DOBTR(size) \ asm volatile("lock; btr" #size " %0, (%1)" \ : \ @@ -267,6 +274,11 @@ struct PicoSpinLock { } #undef FB_DOBTR +#elif FOLLY_A64 + __atomic_fetch_and(&lock_, ~(1 << Bit), __ATOMIC_SEQ_CST); +#else +# error "x64 aarch64 only" +#endif } };