From: compudj@krystal.dyndns.org (Mathieu Desnoyers)
Subject: [ltt-dev] [PATCH 08/12] move whether atomic byte/short exists to uatomic_arch_*.h
Date: Wed, 17 Feb 2010 22:12:28 -0500 [thread overview]
Message-ID: <20100218031228.GD11338@Krystal> (raw)
In-Reply-To: <1266260686-17588-9-git-send-email-pbonzini@redhat.com>
* Paolo Bonzini (pbonzini at redhat.com) wrote:
> And add more generic implementations to uatomic_defaults.h.
>
> Signed-off-by: Paolo Bonzini <pbonzini at redhat.com>
> ---
> tests/test_uatomic.c | 15 +------
> urcu/uatomic_arch_x86.h | 3 +
> urcu/uatomic_defaults.h | 96 +++++++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 101 insertions(+), 13 deletions(-)
>
> diff --git a/tests/test_uatomic.c b/tests/test_uatomic.c
> index c0f36fe..5682655 100644
> --- a/tests/test_uatomic.c
> +++ b/tests/test_uatomic.c
> @@ -1,21 +1,10 @@
> #include <stdio.h>
> #include <assert.h>
> -
> -#define UATOMIC_NO_LINK_ERROR
> #include <urcu/uatomic_arch.h>
>
> -#if (defined(__i386__) || defined(__x86_64__))
> -#define HAS_ATOMIC_BYTE
> -#define HAS_ATOMIC_SHORT
> -#endif
> -
> struct testvals {
> -#ifdef HAS_ATOMIC_BYTE
> unsigned char c;
> -#endif
> -#ifdef HAS_ATOMIC_SHORT
> unsigned short s;
> -#endif
> unsigned int i;
> unsigned long l;
> };
> @@ -54,10 +43,10 @@ do { \
>
> int main(int argc, char **argv)
> {
> -#ifdef HAS_ATOMIC_BYTE
> +#ifdef UATOMIC_HAS_ATOMIC_BYTE
> do_test(&vals.c);
> #endif
> -#ifdef HAS_ATOMIC_SHORT
> +#ifdef UATOMIC_HAS_ATOMIC_SHORT
> do_test(&vals.s);
> #endif
> do_test(&vals.i);
> diff --git a/urcu/uatomic_arch_x86.h b/urcu/uatomic_arch_x86.h
> index 8a81995..f2d0c19 100644
> --- a/urcu/uatomic_arch_x86.h
> +++ b/urcu/uatomic_arch_x86.h
> @@ -23,6 +23,9 @@
> #include <urcu/compiler.h>
> #include <urcu/system.h>
>
> +#define UATOMIC_HAS_ATOMIC_BYTE
> +#define UATOMIC_HAS_ATOMIC_SHORT
> +
> #ifdef __cplusplus
> extern "C" {
> #endif
> diff --git a/urcu/uatomic_defaults.h b/urcu/uatomic_defaults.h
> index 93467dd..2d0af6e 100644
> --- a/urcu/uatomic_defaults.h
> +++ b/urcu/uatomic_defaults.h
> @@ -64,6 +64,14 @@ unsigned long _uatomic_cmpxchg(void *addr, unsigned long old,
> unsigned long _new, int len)
> {
> switch (len) {
> +#ifdef UATOMIC_HAS_ATOMIC_BYTE
> + case 1:
> + return __sync_val_compare_and_swap_1(addr, old, _new);
> +#endif
> +#ifdef UATOMIC_HAS_ATOMIC_SHORT
> + case 2:
> + return __sync_val_compare_and_swap_2(addr, old, _new);
> +#endif
> case 4:
> return __sync_val_compare_and_swap_4(addr, old, _new);
> #if (BITS_PER_LONG == 64)
> @@ -90,6 +98,14 @@ unsigned long _uatomic_add_return(void *addr, unsigned long val,
> int len)
> {
> switch (len) {
> +#ifdef UATOMIC_HAS_ATOMIC_BYTE
> + case 1:
> + return __sync_add_and_fetch_1(addr, val);
> +#endif
> +#ifdef UATOMIC_HAS_ATOMIC_SHORT
> + case 2:
> + return __sync_add_and_fetch_2(addr, val);
> +#endif
> case 4:
> return __sync_add_and_fetch_4(addr, val);
> #if (BITS_PER_LONG == 64)
> @@ -115,6 +131,30 @@ static inline __attribute__((always_inline))
> unsigned long _uatomic_exchange(void *addr, unsigned long val, int len)
> {
> switch (len) {
> +#ifdef UATOMIC_HAS_ATOMIC_BYTE
> + case 1:
> + {
> + unsigned char old;
> +
> + do
> + old = uatomic_read((unsigned char *)addr);
> + while (!__sync_bool_compare_and_swap_1(addr, old, val));
Same here for brackets.
> +
> + return old;
> + }
> +#endif
> +#ifdef UATOMIC_HAS_ATOMIC_SHORT
> + case 2:
> + {
> + unsigned short old;
> +
> + do
> + old = uatomic_read((unsigned short *)addr);
> + while (!__sync_bool_compare_and_swap_2(addr, old, val));
And here.
Thanks,
Mathieu
> +
> + return old;
> + }
> +#endif
> case 4:
> {
> unsigned int old;
> @@ -156,6 +196,34 @@ static inline __attribute__((always_inline))
> unsigned long _uatomic_add_return(void *addr, unsigned long val, int len)
> {
> switch (len) {
> +#ifdef UATOMIC_HAS_ATOMIC_BYTE
> + case 1:
> + {
> + unsigned char old, oldt;
> +
> + oldt = uatomic_read((unsigned char *)addr);
> + do {
> + old = oldt;
> + oldt = _uatomic_cmpxchg(addr, old, old + val, 1);
> + } while (oldt != old);
> +
> + return old + val;
> + }
> +#endif
> +#ifdef UATOMIC_HAS_ATOMIC_SHORT
> + case 2:
> + {
> + unsigned short old, oldt;
> +
> + oldt = uatomic_read((unsigned short *)addr);
> + do {
> + old = oldt;
> + oldt = _uatomic_cmpxchg(addr, old, old + val, 2);
> + } while (oldt != old);
> +
> + return old + val;
> + }
> +#endif
> case 4:
> {
> unsigned int old, oldt;
> @@ -200,6 +268,34 @@ static inline __attribute__((always_inline))
> unsigned long _uatomic_exchange(void *addr, unsigned long val, int len)
> {
> switch (len) {
> +#ifdef UATOMIC_HAS_ATOMIC_BYTE
> + case 1:
> + {
> + unsigned char old, oldt;
> +
> + oldt = uatomic_read((unsigned char *)addr);
> + do {
> + old = oldt;
> + oldt = _uatomic_cmpxchg(addr, old, val, 1);
> + } while (oldt != old);
> +
> + return old;
> + }
> +#endif
> +#ifdef UATOMIC_HAS_ATOMIC_SHORT
> + case 2:
> + {
> + unsigned short old, oldt;
> +
> + oldt = uatomic_read((unsigned short *)addr);
> + do {
> + old = oldt;
> + oldt = _uatomic_cmpxchg(addr, old, val, 2);
> + } while (oldt != old);
> +
> + return old;
> + }
> +#endif
> case 4:
> {
> unsigned int old, oldt;
> --
> 1.6.6
>
>
>
> _______________________________________________
> ltt-dev mailing list
> ltt-dev at lists.casi.polymtl.ca
> http://lists.casi.polymtl.ca/cgi-bin/mailman/listinfo/ltt-dev
>
--
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F BA06 3F25 A8FE 3BAE 9A68
next prev parent reply other threads:[~2010-02-18 3:12 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-15 19:04 [ltt-dev] [PATCH 00/12] provide default definition of uatomic builtins Paolo Bonzini
2010-02-15 19:04 ` [ltt-dev] [PATCH 01/12] use kernel style makefile output Paolo Bonzini
2010-02-15 19:04 ` [ltt-dev] [PATCH 02/12] use autoconf symbolic linking Paolo Bonzini
2010-02-15 19:04 ` [ltt-dev] [PATCH 03/12] add urcu/arch_defaults.h Paolo Bonzini
2010-02-18 2:57 ` Mathieu Desnoyers
2010-02-15 19:04 ` [ltt-dev] [PATCH 04/12] define sync_core for x86 PIC Paolo Bonzini
2010-02-15 19:04 ` [ltt-dev] [PATCH 05/12] remove compat_uatomic_cmpxchg #define from non-x86 Paolo Bonzini
2010-02-15 19:04 ` [ltt-dev] [PATCH 06/12] add uatomic_defaults.h, use it for default definitions Paolo Bonzini
2010-02-18 3:10 ` Mathieu Desnoyers
2010-02-15 19:04 ` [ltt-dev] [PATCH 07/12] use uatomic_defaults.h for common fallback implementations Paolo Bonzini
2010-02-15 19:04 ` [ltt-dev] [PATCH 08/12] move whether atomic byte/short exists to uatomic_arch_*.h Paolo Bonzini
2010-02-18 3:12 ` Mathieu Desnoyers [this message]
2010-02-15 19:04 ` [ltt-dev] [PATCH 09/12] add Alpha support Paolo Bonzini
2010-02-18 3:21 ` Mathieu Desnoyers
2010-02-15 19:04 ` [ltt-dev] [PATCH 10/12] support compiling on unknown architectures Paolo Bonzini
2010-02-18 3:22 ` Mathieu Desnoyers
2010-02-15 19:04 ` [ltt-dev] [PATCH 11/12] avoid multiple evaluation of STORE_SHARED argument Paolo Bonzini
2010-02-18 3:28 ` Mathieu Desnoyers
2010-02-18 8:45 ` Paolo Bonzini
2010-02-15 19:04 ` [ltt-dev] [PATCH 12/12] centralize definition of BITS_PER_LONG Paolo Bonzini
2010-02-18 3:25 ` Mathieu Desnoyers
2010-02-18 8:45 ` Paolo Bonzini
2010-02-18 13:46 ` Mathieu Desnoyers
2010-02-18 15:27 ` Paolo Bonzini
2010-02-18 16:09 ` Mathieu Desnoyers
2010-02-19 19:25 ` [ltt-dev] lock-free data structures (was Re: [PATCH 12/12] centralize definition of BITS_PER_LONG) Paolo Bonzini
2010-02-19 23:51 ` Paul E. McKenney
2010-02-20 0:10 ` Paolo Bonzini
2010-02-20 0:44 ` Paul E. McKenney
2010-02-15 19:04 ` [ltt-dev] [PATCH 13/12] test uatomic_defaults.h Paolo Bonzini
2010-02-19 19:22 [ltt-dev] [PATCH 00/12] provide generic version of uatomic and other per-arch defs Paolo Bonzini
2010-02-19 19:22 ` [ltt-dev] [PATCH 08/12] move whether atomic byte/short exists to uatomic_arch_*.h Paolo Bonzini
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=20100218031228.GD11338@Krystal \
--to=compudj@krystal.dyndns.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