Added asm_volatile_memory
authorOrvid King <blah38621@gmail.com>
Wed, 29 Jul 2015 18:36:32 +0000 (11:36 -0700)
committerfacebook-github-bot-4 <folly-bot@fb.com>
Wed, 29 Jul 2015 20:22:11 +0000 (13:22 -0700)
Summary: This adds `asm_volatile_memory`, which goes along with the same style used by `asm_volatile_pause`.
This also switches the two places in `RWSpinLock.h` that were using inline assembly for this to use the new functions instead.
Closes #260

Reviewed By: @yfeldblum

Differential Revision: D2283541

Pulled By: @sgolemon

folly/Portability.h
folly/RWSpinLock.h

index bce4dd1f06a7d8c5aabba792c741da6e90b63a42..252362a5006fcca7a87b4d2e5e622e0854b78856 100644 (file)
@@ -339,6 +339,14 @@ inline size_t malloc_usable_size(void* ptr) {
 
 namespace folly {
 
+inline void asm_volatile_memory() {
+#if defined(__clang__) || defined(__GNUC__)
+  asm volatile("" : : : "memory");
+#elif defined(_MSC_VER)
+  ::_ReadWriteBarrier();
+#endif
+}
+
 inline void asm_volatile_pause() {
 #if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64))
   ::_mm_pause();
index 359343f80c1536d6c310d8f21cb6a10fc246aef4..8e191d825dcfcacda807fe3279be771fc012dc80 100644 (file)
@@ -525,13 +525,13 @@ class RWTicketSpinLockT : boost::noncopyable {
  private: // Some x64-specific utilities for atomic access to ticket.
   template<class T> static T load_acquire(T* addr) {
     T t = *addr; // acquire barrier
-    asm volatile("" : : : "memory");
+    asm_volatile_memory();
     return t;
   }
 
   template<class T>
   static void store_release(T* addr, T v) {
-    asm volatile("" : : : "memory");
+    asm_volatile_memory();
     *addr = v; // release barrier
   }