diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2011-06-20 10:52:57 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2011-07-20 01:43:14 -0400 |
commit | 07b8ce1ee87d291ff564c02cf878fae973317a52 (patch) | |
tree | 94f07ed2b5d18aef71f1b28193375f88c0c947bc /include/linux/atomic.h | |
parent | f4d6ff89d8e54b68a4322388d26d518d6133fa4e (diff) |
lockless get_write_access/deny_write_access
new helpers: atomic_inc_unless_negative()/atomic_dec_unless_positive()
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'include/linux/atomic.h')
-rw-r--r-- | include/linux/atomic.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/include/linux/atomic.h b/include/linux/atomic.h index ee456c79b0e6..bc6615d4132b 100644 --- a/include/linux/atomic.h +++ b/include/linux/atomic.h | |||
@@ -34,6 +34,32 @@ static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint) | |||
34 | } | 34 | } |
35 | #endif | 35 | #endif |
36 | 36 | ||
37 | #ifndef atomic_inc_unless_negative | ||
38 | static inline int atomic_inc_unless_negative(atomic_t *p) | ||
39 | { | ||
40 | int v, v1; | ||
41 | for (v = 0; v >= 0; v = v1) { | ||
42 | v1 = atomic_cmpxchg(p, v, v + 1); | ||
43 | if (likely(v1 == v)) | ||
44 | return 1; | ||
45 | } | ||
46 | return 0; | ||
47 | } | ||
48 | #endif | ||
49 | |||
50 | #ifndef atomic_dec_unless_positive | ||
51 | static inline int atomic_dec_unless_positive(atomic_t *p) | ||
52 | { | ||
53 | int v, v1; | ||
54 | for (v = 0; v <= 0; v = v1) { | ||
55 | v1 = atomic_cmpxchg(p, v, v - 1); | ||
56 | if (likely(v1 == v)) | ||
57 | return 1; | ||
58 | } | ||
59 | return 0; | ||
60 | } | ||
61 | #endif | ||
62 | |||
37 | #ifndef CONFIG_ARCH_HAS_ATOMIC_OR | 63 | #ifndef CONFIG_ARCH_HAS_ATOMIC_OR |
38 | static inline void atomic_or(int i, atomic_t *v) | 64 | static inline void atomic_or(int i, atomic_t *v) |
39 | { | 65 | { |