From: "Loïc Minier" <lool@dooz.org>
To: qemu-devel@nongnu.org
Cc: "Loïc Minier" <lool@dooz.org>
Subject: [Qemu-devel] [PATCH 1/2] Detect and use GCC atomic builtins for locking
Date: Fri, 19 Feb 2010 22:02:39 +0100 [thread overview]
Message-ID: <1266613360-23069-1-git-send-email-lool@dooz.org> (raw)
---
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
next reply other threads:[~2010-02-19 21:02 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-19 21:02 Loïc Minier [this message]
2010-02-19 21:02 ` [Qemu-devel] [PATCH 2/2] Make spinlock_t types volatile Loïc Minier
2010-02-19 21:42 ` [Qemu-devel] [PATCH 1/2] Detect and use GCC atomic builtins for locking malc
2010-02-20 8:16 ` Loïc Minier
2010-02-20 8:28 ` malc
2010-02-20 9:10 ` Loïc Minier
2010-02-20 17:57 ` malc
2010-02-22 10:25 ` Loïc Minier
2010-02-22 10:47 ` malc
2010-02-28 0:26 ` Paul Brook
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1266613360-23069-1-git-send-email-lool@dooz.org \
--to=lool@dooz.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).