Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Functions
cmpxchg.h File Reference
#include <linux/compiler.h>
#include <asm/alternative.h>
#include <asm/cmpxchg_64.h>

Go to the source code of this file.

Macros

#define __X86_CASE_B   1
 
#define __X86_CASE_W   2
 
#define __X86_CASE_L   4
 
#define __X86_CASE_Q   -1 /* sizeof will never return -1 */
 
#define __xchg_op(ptr, arg, op, lock)
 
#define xchg(ptr, v)   __xchg_op((ptr), (v), xchg, "")
 
#define __raw_cmpxchg(ptr, old, new, size, lock)
 
#define __cmpxchg(ptr, old, new, size)   __raw_cmpxchg((ptr), (old), (new), (size), LOCK_PREFIX)
 
#define __sync_cmpxchg(ptr, old, new, size)   __raw_cmpxchg((ptr), (old), (new), (size), "lock; ")
 
#define __cmpxchg_local(ptr, old, new, size)   __raw_cmpxchg((ptr), (old), (new), (size), "")
 
#define __xadd(ptr, inc, lock)   __xchg_op((ptr), (inc), xadd, lock)
 
#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), "")
 
#define __add(ptr, inc, lock)
 
#define add_smp(ptr, inc)   __add((ptr), (inc), LOCK_PREFIX)
 
#define add_sync(ptr, inc)   __add((ptr), (inc), "lock; ")
 
#define __cmpxchg_double(pfx, p1, p2, o1, o2, n1, n2)
 
#define cmpxchg_double(p1, p2, o1, o2, n1, n2)   __cmpxchg_double(LOCK_PREFIX, p1, p2, o1, o2, n1, n2)
 
#define cmpxchg_double_local(p1, p2, o1, o2, n1, n2)   __cmpxchg_double(, p1, p2, o1, o2, n1, n2)
 

Functions

void __xchg_wrong_size (void) __compiletime_error("Bad argument size for xchg")
 
void __cmpxchg_wrong_size (void) __compiletime_error("Bad argument size for cmpxchg")
 
void __xadd_wrong_size (void) __compiletime_error("Bad argument size for xadd")
 
void __add_wrong_size (void) __compiletime_error("Bad argument size for add")
 

Macro Definition Documentation

#define __add (   ptr,
  inc,
  lock 
)
Value:
({ \
__typeof__ (*(ptr)) __ret = (inc); \
switch (sizeof(*(ptr))) { \
case __X86_CASE_B: \
asm volatile (lock "addb %b1, %0\n" \
: "+m" (*(ptr)) : "qi" (inc) \
: "memory", "cc"); \
break; \
case __X86_CASE_W: \
asm volatile (lock "addw %w1, %0\n" \
: "+m" (*(ptr)) : "ri" (inc) \
: "memory", "cc"); \
break; \
case __X86_CASE_L: \
asm volatile (lock "addl %1, %0\n" \
: "+m" (*(ptr)) : "ri" (inc) \
: "memory", "cc"); \
break; \
case __X86_CASE_Q: \
asm volatile (lock "addq %1, %0\n" \
: "+m" (*(ptr)) : "ri" (inc) \
: "memory", "cc"); \
break; \
default: \
__add_wrong_size(); \
} \
__ret; \
})

Definition at line 170 of file cmpxchg.h.

#define __cmpxchg (   ptr,
  old,
  new,
  size 
)    __raw_cmpxchg((ptr), (old), (new), (size), LOCK_PREFIX)

Definition at line 131 of file cmpxchg.h.

#define __cmpxchg_double (   pfx,
  p1,
  p2,
  o1,
  o2,
  n1,
  n2 
)
Value:
({ \
bool __ret; \
__typeof__(*(p1)) __old1 = (o1), __new1 = (n1); \
__typeof__(*(p2)) __old2 = (o2), __new2 = (n2); \
BUILD_BUG_ON(sizeof(*(p1)) != sizeof(long)); \
BUILD_BUG_ON(sizeof(*(p2)) != sizeof(long)); \
VM_BUG_ON((unsigned long)(p1) % (2 * sizeof(long))); \
VM_BUG_ON((unsigned long)((p1) + 1) != (unsigned long)(p2)); \
asm volatile(pfx "cmpxchg%c4b %2; sete %0" \
: "=a" (__ret), "+d" (__old2), \
"+m" (*(p1)), "+m" (*(p2)) \
: "i" (2 * sizeof(long)), "a" (__old1), \
"b" (__new1), "c" (__new2)); \
__ret; \
})

Definition at line 210 of file cmpxchg.h.

#define __cmpxchg_local (   ptr,
  old,
  new,
  size 
)    __raw_cmpxchg((ptr), (old), (new), (size), "")

Definition at line 137 of file cmpxchg.h.

#define __raw_cmpxchg (   ptr,
  old,
  new,
  size,
  lock 
)

Definition at line 83 of file cmpxchg.h.

#define __sync_cmpxchg (   ptr,
  old,
  new,
  size 
)    __raw_cmpxchg((ptr), (old), (new), (size), "lock; ")

Definition at line 134 of file cmpxchg.h.

#define __X86_CASE_B   1

Definition at line 27 of file cmpxchg.h.

#define __X86_CASE_L   4

Definition at line 29 of file cmpxchg.h.

#define __X86_CASE_Q   -1 /* sizeof will never return -1 */

Definition at line 33 of file cmpxchg.h.

#define __X86_CASE_W   2

Definition at line 28 of file cmpxchg.h.

#define __xadd (   ptr,
  inc,
  lock 
)    __xchg_op((ptr), (inc), xadd, lock)

Definition at line 165 of file cmpxchg.h.

#define __xchg_op (   ptr,
  arg,
  op,
  lock 
)
Value:
({ \
__typeof__ (*(ptr)) __ret = (arg); \
switch (sizeof(*(ptr))) { \
case __X86_CASE_B: \
asm volatile (lock #op "b %b0, %1\n" \
: "+q" (__ret), "+m" (*(ptr)) \
: : "memory", "cc"); \
break; \
case __X86_CASE_W: \
asm volatile (lock #op "w %w0, %1\n" \
: "+r" (__ret), "+m" (*(ptr)) \
: : "memory", "cc"); \
break; \
case __X86_CASE_L: \
asm volatile (lock #op "l %0, %1\n" \
: "+r" (__ret), "+m" (*(ptr)) \
: : "memory", "cc"); \
break; \
case __X86_CASE_Q: \
asm volatile (lock #op "q %q0, %1\n" \
: "+r" (__ret), "+m" (*(ptr)) \
: : "memory", "cc"); \
break; \
default: \
__ ## op ## _wrong_size(); \
} \
__ret; \
})

Definition at line 40 of file cmpxchg.h.

#define add_smp (   ptr,
  inc 
)    __add((ptr), (inc), LOCK_PREFIX)

Definition at line 207 of file cmpxchg.h.

#define add_sync (   ptr,
  inc 
)    __add((ptr), (inc), "lock; ")

Definition at line 208 of file cmpxchg.h.

#define cmpxchg_double (   p1,
  p2,
  o1,
  o2,
  n1,
  n2 
)    __cmpxchg_double(LOCK_PREFIX, p1, p2, o1, o2, n1, n2)

Definition at line 227 of file cmpxchg.h.

#define cmpxchg_double_local (   p1,
  p2,
  o1,
  o2,
  n1,
  n2 
)    __cmpxchg_double(, p1, p2, o1, o2, n1, n2)

Definition at line 230 of file cmpxchg.h.

#define xadd (   ptr,
  inc 
)    __xadd((ptr), (inc), LOCK_PREFIX)

Definition at line 166 of file cmpxchg.h.

#define xadd_local (   ptr,
  inc 
)    __xadd((ptr), (inc), "")

Definition at line 168 of file cmpxchg.h.

#define xadd_sync (   ptr,
  inc 
)    __xadd((ptr), (inc), "lock; ")

Definition at line 167 of file cmpxchg.h.

#define xchg (   ptr,
  v 
)    __xchg_op((ptr), (v), xchg, "")

Definition at line 76 of file cmpxchg.h.

Function Documentation

void __add_wrong_size ( void  )
void __cmpxchg_wrong_size ( void  )
void __xadd_wrong_size ( void  )
void __xchg_wrong_size ( void  )