]> git.karo-electronics.de Git - karo-tx-linux.git/blob - include/linux/refcount.h
Merge tag 'for-linus-4.11b-rc4-tag' of git://git.kernel.org/pub/scm/linux/kernel...
[karo-tx-linux.git] / include / linux / refcount.h
1 #ifndef _LINUX_REFCOUNT_H
2 #define _LINUX_REFCOUNT_H
3
4 #include <linux/atomic.h>
5 #include <linux/mutex.h>
6 #include <linux/spinlock.h>
7 #include <linux/kernel.h>
8
9 typedef struct refcount_struct {
10         atomic_t refs;
11 } refcount_t;
12
13 #define REFCOUNT_INIT(n)        { .refs = ATOMIC_INIT(n), }
14
15 static inline void refcount_set(refcount_t *r, unsigned int n)
16 {
17         atomic_set(&r->refs, n);
18 }
19
20 static inline unsigned int refcount_read(const refcount_t *r)
21 {
22         return atomic_read(&r->refs);
23 }
24
25 extern __must_check bool refcount_add_not_zero(unsigned int i, refcount_t *r);
26 extern void refcount_add(unsigned int i, refcount_t *r);
27
28 extern __must_check bool refcount_inc_not_zero(refcount_t *r);
29 extern void refcount_inc(refcount_t *r);
30
31 extern __must_check bool refcount_sub_and_test(unsigned int i, refcount_t *r);
32 extern void refcount_sub(unsigned int i, refcount_t *r);
33
34 extern __must_check bool refcount_dec_and_test(refcount_t *r);
35 extern void refcount_dec(refcount_t *r);
36
37 extern __must_check bool refcount_dec_if_one(refcount_t *r);
38 extern __must_check bool refcount_dec_not_one(refcount_t *r);
39 extern __must_check bool refcount_dec_and_mutex_lock(refcount_t *r, struct mutex *lock);
40 extern __must_check bool refcount_dec_and_lock(refcount_t *r, spinlock_t *lock);
41
42 #endif /* _LINUX_REFCOUNT_H */