From: Orvid King Date: Wed, 29 Jul 2015 18:36:32 +0000 (-0700) Subject: Added asm_volatile_memory X-Git-Tag: v0.53.0~34 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=d6a6bb23e459154202c2d32d50f5ac2d1e887e56;p=folly.git Added asm_volatile_memory 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 --- diff --git a/folly/Portability.h b/folly/Portability.h index bce4dd1f..252362a5 100644 --- a/folly/Portability.h +++ b/folly/Portability.h @@ -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(); diff --git a/folly/RWSpinLock.h b/folly/RWSpinLock.h index 359343f8..8e191d82 100644 --- a/folly/RWSpinLock.h +++ b/folly/RWSpinLock.h @@ -525,13 +525,13 @@ class RWTicketSpinLockT : boost::noncopyable { private: // Some x64-specific utilities for atomic access to ticket. template static T load_acquire(T* addr) { T t = *addr; // acquire barrier - asm volatile("" : : : "memory"); + asm_volatile_memory(); return t; } template static void store_release(T* addr, T v) { - asm volatile("" : : : "memory"); + asm_volatile_memory(); *addr = v; // release barrier }