Add a compiler and hardware memory barrier macro

This commit is contained in:
Nils O. Selåsdal
2013-11-13 23:18:42 +01:00
parent bae3027720
commit 8fd26cd810
+12
View File
@@ -40,6 +40,18 @@
*/ */
#define UC_ATOMIC_CAS(ptr, oldval, newval) __sync_val_compare_and_swap((ptr), (oldval), (newval)) #define UC_ATOMIC_CAS(ptr, oldval, newval) __sync_val_compare_and_swap((ptr), (oldval), (newval))
/** Issue a full (hardware) memory barrier.
* preventing the cpu to move load/stores across
* the barrier. (This implies a compiler barrier as well)
* */
#define UC_MEM_BARRIER() __sync_synchronize()
/** Issue a full compiler/software only memory barrier
* preventing compiler optimization to move load/stores across
* the barrier.
* */
#define UC_COMPILER_BARRIER() __asm__ __volatile__("": : :"memory")
#else #else
#error "No atomic operations implemented for this compiler" #error "No atomic operations implemented for this compiler"
#endif #endif