From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46903) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b1QM4-0002um-Bo for qemu-devel@nongnu.org; Fri, 13 May 2016 23:35:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b1QLy-0005Ki-VG for qemu-devel@nongnu.org; Fri, 13 May 2016 23:35:04 -0400 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:39542) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b1QLw-0005JW-N7 for qemu-devel@nongnu.org; Fri, 13 May 2016 23:34:58 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id C496D20B88 for ; Fri, 13 May 2016 23:34:41 -0400 (EDT) From: "Emilio G. Cota" Date: Fri, 13 May 2016 23:34:21 -0400 Message-Id: <1463196873-17737-7-git-send-email-cota@braap.org> In-Reply-To: <1463196873-17737-1-git-send-email-cota@braap.org> References: <1463196873-17737-1-git-send-email-cota@braap.org> Subject: [Qemu-devel] [PATCH v5 06/18] atomics: add atomic_read_acquire and atomic_set_release List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: QEMU Developers , MTTCG Devel Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Paolo Bonzini , Peter Crosthwaite , Richard Henderson , Sergey Fedorov 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 --- 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