12345678910111213141516171819202122232425262728293031323334353637 |
- #ifndef ATOMIC_H
- #define ATOMIC_H
- #include "irq.h"
- /*
- * Atomic operations (implemented by locking out IRQ)
- */
- #define atomic_cmpxchg(__p,__o,__n) \
- ({ \
- volatile __typeof__(__p) *___p = &(__p); \
- irqmask_t __irq = disable_irqs(); \
- bool __ok = *___p == (__o); \
- if (__ok) \
- *___p = (__n); \
- restore_irqs(__irq); \
- __ok; \
- })
- #define atomic_xchg_op(__p,__var,__op) \
- ({ \
- volatile __typeof__(__p) *___p = &(__p); \
- irqmask_t __irq = disable_irqs(); \
- __typeof__(*___p) __var = *___p; \
- *___p = (__op); \
- restore_irqs(__irq); \
- __var; \
- })
- #define atomic_xchg(__p,__a) atomic_xchg_op(__p,__v,__v)
- #define atomic_xchg_add(__p,__a) atomic_xchg_op(__p,__v,__v + (__a))
- #define atomic_xchg_and(__p,__a) atomic_xchg_op(__p,__v,__v & (__a))
- #define atomic_xchg_or(__p,__a) atomic_xchg_op(__p,__v,__v | (__a))
- #define atomic_xchg_xor(__p,__a) atomic_xchg_op(__p,__v,__v ^ (__a))
- #endif /* ATOMIC_H */
|