Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 269548
b: refs/heads/master
c: 433b352
h: refs/heads/master
v: v3
  • Loading branch information
Jeremy Fitzhardinge authored and H. Peter Anvin committed Aug 29, 2011
1 parent cbb22be commit daed244
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: e9826380d83d1bda3ee5663bf3fa4667a6fbe60a
refs/heads/master: 433b3520616be694e0aa777089346c8718c91a7b
43 changes: 43 additions & 0 deletions trunk/arch/x86/include/asm/cmpxchg.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
/* Non-existant functions to indicate usage errors at link time. */
extern void __xchg_wrong_size(void);
extern void __cmpxchg_wrong_size(void);
extern void __xadd_wrong_size(void);

/*
* Constants for operation sizes. On 32-bit, the 64-bit size it set to
Expand Down Expand Up @@ -157,4 +158,46 @@ extern void __cmpxchg_wrong_size(void);
__cmpxchg_local((ptr), (old), (new), sizeof(*ptr))
#endif

#define __xadd(ptr, inc, lock) \
({ \
__typeof__ (*(ptr)) __ret = (inc); \
switch (sizeof(*(ptr))) { \
case __X86_CASE_B: \
asm volatile (lock "xaddb %b0, %1\n" \
: "+r" (__ret), "+m" (*(ptr)) \
: : "memory", "cc"); \
break; \
case __X86_CASE_W: \
asm volatile (lock "xaddw %w0, %1\n" \
: "+r" (__ret), "+m" (*(ptr)) \
: : "memory", "cc"); \
break; \
case __X86_CASE_L: \
asm volatile (lock "xaddl %0, %1\n" \
: "+r" (__ret), "+m" (*(ptr)) \
: : "memory", "cc"); \
break; \
case __X86_CASE_Q: \
asm volatile (lock "xaddq %q0, %1\n" \
: "+r" (__ret), "+m" (*(ptr)) \
: : "memory", "cc"); \
break; \
default: \
__xadd_wrong_size(); \
} \
__ret; \
})

/*
* xadd() adds "inc" to "*ptr" and atomically returns the previous
* value of "*ptr".
*
* xadd() is locked when multiple CPUs are online
* xadd_sync() is always locked
* xadd_local() is never locked
*/
#define xadd(ptr, inc) __xadd((ptr), (inc), LOCK_PREFIX)
#define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
#define xadd_local(ptr, inc) __xadd((ptr), (inc), "")

#endif /* ASM_X86_CMPXCHG_H */

0 comments on commit daed244

Please sign in to comment.