summaryrefslogtreecommitdiff
path: root/include/linux/atomic.h
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2011-06-20 10:52:57 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2011-07-20 01:43:14 -0400
commit07b8ce1ee87d291ff564c02cf878fae973317a52 (patch)
tree94f07ed2b5d18aef71f1b28193375f88c0c947bc /include/linux/atomic.h
parentf4d6ff89d8e54b68a4322388d26d518d6133fa4e (diff)
downloadlwn-07b8ce1ee87d291ff564c02cf878fae973317a52.tar.gz
lwn-07b8ce1ee87d291ff564c02cf878fae973317a52.zip
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.h26
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)
}
#endif
+#ifndef atomic_inc_unless_negative
+static inline int atomic_inc_unless_negative(atomic_t *p)
+{
+ int v, v1;
+ for (v = 0; v >= 0; v = v1) {
+ v1 = atomic_cmpxchg(p, v, v + 1);
+ if (likely(v1 == v))
+ return 1;
+ }
+ return 0;
+}
+#endif
+
+#ifndef atomic_dec_unless_positive
+static inline int atomic_dec_unless_positive(atomic_t *p)
+{
+ int v, v1;
+ for (v = 0; v <= 0; v = v1) {
+ v1 = atomic_cmpxchg(p, v, v - 1);
+ if (likely(v1 == v))
+ return 1;
+ }
+ return 0;
+}
+#endif
+
#ifndef CONFIG_ARCH_HAS_ATOMIC_OR
static inline void atomic_or(int i, atomic_t *v)
{