about summary refs log tree commit diff
path: root/sysdeps/ia64/bits
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>2003-03-26 04:02:03 +0000
committerRoland McGrath <roland@gnu.org>2003-03-26 04:02:03 +0000
commit859e708f0e44d50deff617c7fd939f4fba295afb (patch)
treec02276928e6c984391f089af6b54f81220165d0e /sysdeps/ia64/bits
parentdd410d4d4585883d02aa497f4227551c5c4cf811 (diff)
downloadglibc-859e708f0e44d50deff617c7fd939f4fba295afb.tar.gz
glibc-859e708f0e44d50deff617c7fd939f4fba295afb.tar.xz
glibc-859e708f0e44d50deff617c7fd939f4fba295afb.zip
* csu/tst-atomic.c (do_test): Add some new
	atomic_compare_and_exchange_val_acq, atomic_add_zero,
	atomic_compare_and_exchange_bool_acq and atomic_add_negative tests.
	* include/atomic.h (atomic_add_negative, atomic_add_zero):
	Prefix local variable so that it doesn't clash with the one
	in atomic_exchange_and_add.
	* sysdeps/ia64/bits/atomic.h (atomic_exchange): Fix for long/void *
	pointers.
	(atomic_exchange_and_add): Implement using __sync_fetch_and_add_?i.
	* sysdeps/powerpc/bits/atomic.h (atomic_exchange_and_add): Force
	value into register.
	* sysdeps/s390/bits/atomic.h (__arch_compare_and_exchange_val_64_acq):
	Cast newval to long.
	* sysdeps/x86_64/bits/atomic.h
	(__arch_compare_and_exchange_val_64_acq): Cast newval and oldval to
	long.
	(atomic_exchange): Cast newvalue to long if sizeof == 8.
	(atomic_exchange_and_add): Cast value to long if sizeof == 8.
	(atomic_add, atomic_add_negative, atomic_add_zero): Likewise.
	(atomic_bit_set): Shift 1L up in all cases to shut up warnings.
Diffstat (limited to 'sysdeps/ia64/bits')
-rw-r--r--sysdeps/ia64/bits/atomic.h33
1 files changed, 18 insertions, 15 deletions
diff --git a/sysdeps/ia64/bits/atomic.h b/sysdeps/ia64/bits/atomic.h
index 68d79fa9ec..b6522b3272 100644
--- a/sysdeps/ia64/bits/atomic.h
+++ b/sysdeps/ia64/bits/atomic.h
@@ -75,23 +75,26 @@ typedef uintmax_t uatomic_max_t;
 
 /* Atomically store newval and return the old value.  */
 #define atomic_exchange(mem, value) \
-  __sync_lock_test_and_set_si (mem, value)
+  ({ __typeof (*mem) __result;						      \
+     if (sizeof (*mem) == 4)						      \
+       __result = __sync_lock_test_and_set_si ((int *) (mem), (int) (value)); \
+     else if (sizeof (*mem) == 8)					      \
+       __result = __sync_lock_test_and_set_di ((long *) (mem),		      \
+					       (long) (value));		      \
+     else								      \
+       abort ();							      \
+     __result; })
+       
 
 #define atomic_exchange_and_add(mem, value) \
-  ({ __typeof (*mem) __oldval, __val;					      \
-     __typeof (mem) __memp = (mem);					      \
-     __typeof (*mem) __value = (value);					      \
-									      \
-     __val = (*__memp);							      \
-     do									      \
-       {								      \
-	 __oldval = __val;						      \
-	 __val = atomic_compare_and_exchange_val_acq (__memp,		      \
-						      __oldval + __value,     \
-						      __oldval);	      \
-       }								      \
-     while (__builtin_expect (__val != __oldval, 0));			      \
-     __oldval; })
+  ({ __typeof (*mem) __result;						      \
+     if (sizeof (*mem) == 4)						      \
+       __result = __sync_fetch_and_add_si ((int *) (mem), (int) (value));     \
+     else if (sizeof (*mem) == 8)					      \
+       __result = __sync_fetch_and_add_di ((long *) (mem), (long) (value));   \
+     else								      \
+       abort ();							      \
+     __result; })
 
 #define atomic_decrement_if_positive(mem) \
   ({ __typeof (*mem) __oldval, __val;					      \