From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48491) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c1fqh-0001k5-He for qemu-devel@nongnu.org; Tue, 01 Nov 2016 16:40:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c1fqe-0008Rm-GD for qemu-devel@nongnu.org; Tue, 01 Nov 2016 16:39:59 -0400 Received: from mail-yb0-x244.google.com ([2607:f8b0:4002:c09::244]:35191) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1c1fqe-0008RY-BP for qemu-devel@nongnu.org; Tue, 01 Nov 2016 16:39:56 -0400 Received: by mail-yb0-x244.google.com with SMTP id e129so790191yba.2 for ; Tue, 01 Nov 2016 13:39:56 -0700 (PDT) From: Pranith Kumar Date: Tue, 1 Nov 2016 16:39:53 -0400 Message-Id: <20161101203953.18065-1-bobby.prani@gmail.com> Subject: [Qemu-devel] [PATCH] atomic.h: Use __atomic_load_n() primitive List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini , "Emilio G. Cota" , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Richard Henderson , "open list:All patches CC here" Use __atomic_load_n() primitive saving a load and store to a local variable. Signed-off-by: Pranith Kumar --- include/qemu/atomic.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/include/qemu/atomic.h b/include/qemu/atomic.h index 878fa07..be44094 100644 --- a/include/qemu/atomic.h +++ b/include/qemu/atomic.h @@ -120,20 +120,22 @@ * same, but this slows down atomic_rcu_read unnecessarily. */ #ifdef __SANITIZE_THREAD__ -#define atomic_rcu_read__nocheck(ptr, valptr) \ - __atomic_load(ptr, valptr, __ATOMIC_CONSUME); +#define atomic_rcu_read__nocheck(ptr) \ + __atomic_load_n(ptr, __ATOMIC_CONSUME); #else -#define atomic_rcu_read__nocheck(ptr, valptr) \ - __atomic_load(ptr, valptr, __ATOMIC_RELAXED); \ - smp_read_barrier_depends(); +#define atomic_rcu_read__nocheck(ptr) \ + ({ \ + typeof_strip_qual(*ptr) _val; \ + __atomic_load(ptr, &_val, __ATOMIC_RELAXED); \ + smp_read_barrier_depends(); \ + _val; \ + }) #endif #define atomic_rcu_read(ptr) \ ({ \ QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \ - typeof_strip_qual(*ptr) _val; \ - atomic_rcu_read__nocheck(ptr, &_val); \ - _val; \ + atomic_rcu_read__nocheck(ptr); \ }) #define atomic_rcu_set(ptr, i) do { \ @@ -144,9 +146,7 @@ #define atomic_load_acquire(ptr) \ ({ \ QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \ - typeof_strip_qual(*ptr) _val; \ - __atomic_load(ptr, &_val, __ATOMIC_ACQUIRE); \ - _val; \ + __atomic_load_n(ptr, __ATOMIC_ACQUIRE); \ }) #define atomic_store_release(ptr, i) do { \ -- 2.10.2