]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - include/linux/refcount.h
rhashtable: compact struct rhashtable_params
[mirror_ubuntu-artful-kernel.git] / include / linux / refcount.h
CommitLineData
f405df5d
PZ
1#ifndef _LINUX_REFCOUNT_H
2#define _LINUX_REFCOUNT_H
3
f405df5d 4#include <linux/atomic.h>
f405df5d
PZ
5#include <linux/mutex.h>
6#include <linux/spinlock.h>
318b1ded 7#include <linux/kernel.h>
f405df5d 8
f405df5d
PZ
9typedef struct refcount_struct {
10 atomic_t refs;
11} refcount_t;
12
13#define REFCOUNT_INIT(n) { .refs = ATOMIC_INIT(n), }
14
15static inline void refcount_set(refcount_t *r, unsigned int n)
16{
17 atomic_set(&r->refs, n);
18}
19
20static inline unsigned int refcount_read(const refcount_t *r)
21{
22 return atomic_read(&r->refs);
23}
24
29dee3c0
PZ
25extern __must_check bool refcount_add_not_zero(unsigned int i, refcount_t *r);
26extern void refcount_add(unsigned int i, refcount_t *r);
f405df5d 27
29dee3c0
PZ
28extern __must_check bool refcount_inc_not_zero(refcount_t *r);
29extern void refcount_inc(refcount_t *r);
f405df5d 30
29dee3c0
PZ
31extern __must_check bool refcount_sub_and_test(unsigned int i, refcount_t *r);
32extern void refcount_sub(unsigned int i, refcount_t *r);
f405df5d 33
29dee3c0
PZ
34extern __must_check bool refcount_dec_and_test(refcount_t *r);
35extern void refcount_dec(refcount_t *r);
f405df5d 36
29dee3c0
PZ
37extern __must_check bool refcount_dec_if_one(refcount_t *r);
38extern __must_check bool refcount_dec_not_one(refcount_t *r);
39extern __must_check bool refcount_dec_and_mutex_lock(refcount_t *r, struct mutex *lock);
40extern __must_check bool refcount_dec_and_lock(refcount_t *r, spinlock_t *lock);
f405df5d
PZ
41
42#endif /* _LINUX_REFCOUNT_H */