]>
git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blob - include/linux/atomic.h
1 #ifndef _LINUX_ATOMIC_H
2 #define _LINUX_ATOMIC_H
3 #include <asm/atomic.h>
6 * atomic_inc_not_zero - increment unless the number is zero
7 * @v: pointer of type atomic_t
9 * Atomically increments @v by 1, so long as @v is non-zero.
10 * Returns non-zero if @v was non-zero, and zero otherwise.
12 #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
15 * atomic_inc_not_zero_hint - increment if not null
16 * @v: pointer of type atomic_t
17 * @hint: probable value of the atomic before the increment
19 * This version of atomic_inc_not_zero() gives a hint of probable
20 * value of the atomic. This helps processor to not read the memory
21 * before doing the atomic read/modify/write cycle, lowering
22 * number of bus transactions on some arches.
24 * Returns: 0 if increment was not done, 1 otherwise.
26 #ifndef atomic_inc_not_zero_hint
27 static inline int atomic_inc_not_zero_hint(atomic_t
*v
, int hint
)
31 /* sanity test, should be removed by compiler if hint is a constant */
33 return atomic_inc_not_zero(v
);
36 val
= atomic_cmpxchg(v
, c
, c
+ 1);
46 #ifndef atomic_inc_unless_negative
47 static inline int atomic_inc_unless_negative(atomic_t
*p
)
50 for (v
= 0; v
>= 0; v
= v1
) {
51 v1
= atomic_cmpxchg(p
, v
, v
+ 1);
59 #ifndef atomic_dec_unless_positive
60 static inline int atomic_dec_unless_positive(atomic_t
*p
)
63 for (v
= 0; v
<= 0; v
= v1
) {
64 v1
= atomic_cmpxchg(p
, v
, v
- 1);
72 #ifndef CONFIG_ARCH_HAS_ATOMIC_OR
73 static inline void atomic_or(int i
, atomic_t
*v
)
81 } while (atomic_cmpxchg(v
, old
, new) != old
);
83 #endif /* #ifndef CONFIG_ARCH_HAS_ATOMIC_OR */
85 #endif /* _LINUX_ATOMIC_H */