[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v5 06/18] atomics: add atomic_read_acquire and atomi
From: |
Emilio G. Cota |
Subject: |
[Qemu-devel] [PATCH v5 06/18] atomics: add atomic_read_acquire and atomic_set_release |
Date: |
Fri, 13 May 2016 23:34:21 -0400 |
When __atomic is not available, we use full memory barriers instead
of smp/wmb, since acquire/release barriers apply to all memory
operations and not just to loads/stores, respectively.
Signed-off-by: Emilio G. Cota <address@hidden>
---
include/qemu/atomic.h | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/include/qemu/atomic.h b/include/qemu/atomic.h
index 6061a46..1766c22 100644
--- a/include/qemu/atomic.h
+++ b/include/qemu/atomic.h
@@ -56,6 +56,21 @@
__atomic_store(ptr, &_val, __ATOMIC_RELAXED); \
} while(0)
+/* atomic read/set with acquire/release barrier */
+#define atomic_read_acquire(ptr) \
+ ({ \
+ QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \
+ typeof(*ptr) _val; \
+ __atomic_load(ptr, &_val, __ATOMIC_ACQUIRE); \
+ _val; \
+ })
+
+#define atomic_set_release(ptr, i) do { \
+ QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \
+ typeof(*ptr) _val = (i); \
+ __atomic_store(ptr, &_val, __ATOMIC_RELEASE); \
+} while(0)
+
/* Atomic RCU operations imply weak memory barriers */
#define atomic_rcu_read(ptr) \
@@ -243,6 +258,18 @@
#define atomic_read(ptr) (*(__typeof__(*ptr) volatile*) (ptr))
#define atomic_set(ptr, i) ((*(__typeof__(*ptr) volatile*) (ptr)) = (i))
+/* atomic read/set with acquire/release barrier */
+#define atomic_read_acquire(ptr) ({ \
+ typeof(*ptr) _val = atomic_read(ptr); \
+ smp_mb(); \
+ _val; \
+})
+
+#define atomic_set_release(ptr, i) do { \
+ smp_mb(); \
+ atomic_set(ptr, i); \
+} while (0)
+
/**
* atomic_rcu_read - reads a RCU-protected pointer to a local variable
* into a RCU read-side critical section. The pointer can later be safely
--
2.5.0
- Re: [Qemu-devel] [PATCH v5 07/18] qemu-thread: add simple test-and-set spinlock, (continued)
[Qemu-devel] [PATCH v5 18/18] translate-all: add tb hash bucket info to 'info jit' dump, Emilio G. Cota, 2016/05/13
[Qemu-devel] [PATCH v5 04/18] include/processor.h: define cpu_relax(), Emilio G. Cota, 2016/05/13
[Qemu-devel] [PATCH v5 06/18] atomics: add atomic_read_acquire and atomic_set_release,
Emilio G. Cota <=
[Qemu-devel] [PATCH v5 13/18] qht: support parallel writes, Emilio G. Cota, 2016/05/13
[Qemu-devel] [PATCH v5 10/18] qdist: add module to represent frequency distributions of data, Emilio G. Cota, 2016/05/13