fix PicoSpinLock for aarch64 and allow PackedSyncPtr to compile for aarch64
authorStephen Chen <tracelog@fb.com>
Sat, 20 May 2017 03:59:15 +0000 (20:59 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Sat, 20 May 2017 04:06:38 +0000 (21:06 -0700)
Summary:
Looks like we never tried to compile or run the PicoSpinLock under aarch64. There were two problems:

if sizeof(IntType) is 64, we try to do
  1 << 63
in lock and unlock. This doesn't compile because sizeof(1) is 32.

Also for try_lock, we were returning the data instead of checking for the locked bit.

Reviewed By: djwatson, yfeldblum

Differential Revision: D5091656

fbshipit-source-id: 4f81b8b32633e87b491548a1a24b9bcf20264063

folly/PackedSyncPtr.h
folly/PicoSpinLock.h

index 64337674f5f3a53b1dca735f94db26684aaecf34..e11588e8419540a32f5ff80e38749253c1f134b1 100644 (file)
@@ -18,8 +18,8 @@
 
 #include <folly/Portability.h>
 
-#if !FOLLY_X64 && !FOLLY_PPC64
-# error "PackedSyncPtr is x64 and ppc64 specific code."
+#if !FOLLY_X64 && !FOLLY_PPC64 && !FOLLY_A64
+# error "PackedSyncPtr is x64, ppc64 or aarch64 specific code."
 #endif
 
 /*
index 8ee98b848fb29b58fe5328c088e7f590a5fcc4b8..485050f136c9ee895af8e28a3d2111583a49b9da 100644 (file)
@@ -171,7 +171,9 @@ struct PicoSpinLock {
 
 #undef FB_DOBTS
 #elif FOLLY_A64
-    ret = __atomic_fetch_or(&lock_, 1 << Bit, __ATOMIC_SEQ_CST);
+    ret =
+        !(__atomic_fetch_or(&lock_, kLockBitMask_, __ATOMIC_SEQ_CST) &
+          kLockBitMask_);
 #elif FOLLY_PPC64
 #define FB_DOBTS(size)                                 \
     asm volatile("\teieio\n"                           \
@@ -252,7 +254,7 @@ struct PicoSpinLock {
 
 #undef FB_DOBTR
 #elif FOLLY_A64
-    __atomic_fetch_and(&lock_, ~(1 << Bit), __ATOMIC_SEQ_CST);
+    __atomic_fetch_and(&lock_, ~kLockBitMask_, __ATOMIC_SEQ_CST);
 #elif FOLLY_PPC64
 #define FB_DOBTR(size)                                 \
     asm volatile("\teieio\n"                           \