From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NiZzw-0000Vk-HZ for qemu-devel@nongnu.org; Fri, 19 Feb 2010 16:02:52 -0500 Received: from [199.232.76.173] (port=41347 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NiZzv-0000VN-Ul for qemu-devel@nongnu.org; Fri, 19 Feb 2010 16:02:51 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NiZzu-0004vx-6E for qemu-devel@nongnu.org; Fri, 19 Feb 2010 16:02:51 -0500 Received: from duck.dooz.org ([194.146.227.125]:37078) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NiZzt-0004v3-M7 for qemu-devel@nongnu.org; Fri, 19 Feb 2010 16:02:49 -0500 From: =?UTF-8?q?Lo=C3=AFc=20Minier?= Date: Fri, 19 Feb 2010 22:02:39 +0100 Message-Id: <1266613360-23069-1-git-send-email-lool@dooz.org> Subject: [Qemu-devel] [PATCH 1/2] Detect and use GCC atomic builtins for locking List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Lo=C3=AFc=20Minier?= --- configure | 17 +++++++++++++++++ qemu-lock.h | 13 +++++++++++++ 2 files changed, 30 insertions(+), 0 deletions(-) diff --git a/configure b/configure index 0a84b0e..b33f045 100755 --- a/configure +++ b/configure @@ -1823,6 +1823,20 @@ if compile_prog "" ""; then fi ########################################## +# check if we have gcc atomic built-ins +gcc_atomic_builtins=no +cat > $TMPC << EOF +int main(void) { + int i; + __sync_lock_test_and_set(&i, 1); + __sync_lock_release(&i); +} +EOF +if compile_prog "" ""; then + gcc_atomic_builtins=yes +fi + +########################################## # check if we have fdatasync fdatasync=no @@ -2168,6 +2182,9 @@ fi if test "$gcc_attribute_warn_unused_result" = "yes" ; then echo "CONFIG_GCC_ATTRIBUTE_WARN_UNUSED_RESULT=y" >> $config_host_mak fi +if test "$gcc_atomic_builtins" = "yes" ; then + echo "CONFIG_GCC_ATOMIC_BUILTINS=y" >> $config_host_mak +fi if test "$fdatasync" = "yes" ; then echo "CONFIG_FDATASYNC=y" >> $config_host_mak fi diff --git a/qemu-lock.h b/qemu-lock.h index 9a3e6ac..5c8eb34 100644 --- a/qemu-lock.h +++ b/qemu-lock.h @@ -33,6 +33,14 @@ #else +#ifdef CONFIG_GCC_ATOMIC_BUILTINS +typedef int spinlock_t; + +#define SPIN_LOCK_UNLOCKED 0 + +#define resetlock(p) __sync_lock_release((p)) +#else /* CONFIG_GCC_ATOMIC_BUILTINS */ + #if defined(__hppa__) typedef int spinlock_t[4]; @@ -56,7 +64,11 @@ static inline void resetlock (spinlock_t *p) } #endif +#endif /* !CONFIG_GCC_ATOMIC_BUILTINS */ +#ifdef CONFIG_GCC_ATOMIC_BUILTINS +#define testandset(p) __sync_lock_test_and_set((p), 1) +#else /* CONFIG_GCC_ATOMIC_BUILTINS */ #if defined(_ARCH_PPC) static inline int testandset (int *p) { @@ -213,6 +225,7 @@ static inline int testandset (int *p) #else #error unimplemented CPU support #endif +#endif /* !CONFIG_GCC_ATOMIC_BUILTINS */ #if defined(CONFIG_USER_ONLY) static inline void spin_lock(spinlock_t *lock) -- 1.7.0