diff options
Diffstat (limited to 'sysdeps/i386')
-rw-r--r-- | sysdeps/i386/i486/bits/atomic.h | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/sysdeps/i386/i486/bits/atomic.h b/sysdeps/i386/i486/bits/atomic.h index 87739c6cc6..e22e560a38 100644 --- a/sysdeps/i386/i486/bits/atomic.h +++ b/sysdeps/i386/i486/bits/atomic.h @@ -119,6 +119,29 @@ typedef uintmax_t uatomic_max_t; #endif +/* Note that we need no lock prefix. */ +#define atomic_exchange(mem, newvalue) \ + ({ __typeof (*mem) result; \ + if (sizeof (*mem) == 1) \ + __asm __volatile ("xchgb %b0, %1" \ + : "=r" (result), "=m" (*mem) \ + : "0" (newvalue), "1" (*mem)); \ + else if (sizeof (*mem) == 2) \ + __asm __volatile ("xchgw %w0, %1" \ + : "=r" (result), "=m" (*mem) \ + : "0" (newvalue), "1" (*mem)); \ + else if (sizeof (*mem) == 4) \ + __asm __volatile ("xchgl %0, %1" \ + : "=r" (result), "=m" (*mem) \ + : "0" (newvalue), "1" (*mem)); \ + else \ + { \ + result = 0; \ + abort (); \ + } \ + result; }) + + #define atomic_exchange_and_add(mem, value) \ ({ __typeof (*mem) result; \ __typeof (value) addval = (value); \ |