blob: fea109c5f0605c1201bc5a3036d83518fd8feb59 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
/* Public domain. */
#ifndef _LINUX_REFCOUNT_H
#define _LINUX_REFCOUNT_H
#include <sys/types.h>
#include <linux/atomic.h>
typedef atomic_t refcount_t;
static inline bool
refcount_dec_and_test(uint32_t *p)
{
return atomic_dec_and_test(p);
}
static inline bool
refcount_inc_not_zero(uint32_t *p)
{
return atomic_inc_not_zero(p);
}
static inline void
refcount_set(uint32_t *p, int v)
{
atomic_set(p, v);
}
static inline bool
refcount_dec_and_lock_irqsave(volatile int *v, struct mutex *lock,
unsigned long *flags)
{
if (atomic_add_unless(v, -1, 1))
return false;
mtx_enter(lock);
if (atomic_dec_return(v) == 0)
return true;
mtx_leave(lock);
return false;
}
#endif
|