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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
#ifndef _SPL_ATOMIC_COMPAT_H
#define _SPL_ATOMIC_COMPAT_H
#include <asm/atomic.h>
#include <spl_config.h>
#ifndef HAVE_ATOMIC64_T
#include <linux/spinlock.h>
typedef struct {
spinlock_t lock;
__s64 val;
} atomic64_t;
#define ATOMIC64_INIT(i) { .lock = SPIN_LOCK_UNLOCKED, .val = (i) }
static inline void atomic64_add(__s64 i, atomic64_t *v)
{
unsigned long flags;
spin_lock_irqsave(&v->lock, flags);
v->val += i;
spin_unlock_irqrestore(&v->lock, flags);
}
static inline void atomic64_sub(__s64 i, atomic64_t *v)
{
unsigned long flags;
spin_lock_irqsave(&v->lock, flags);
v->val -= i;
spin_unlock_irqrestore(&v->lock, flags);
}
static inline __s64 atomic64_read(atomic64_t *v)
{
unsigned long flags;
__s64 r;
spin_lock_irqsave(&v->lock, flags);
r = v->val;
spin_unlock_irqrestore(&v->lock, flags);
return r;
}
static inline void atomic64_set(atomic64_t *v, __s64 i)
{
unsigned long flags;
spin_lock_irqsave(&v->lock, flags);
v->val = i;
spin_unlock_irqrestore(&v->lock, flags);
}
#endif /* HAVE_ATOMIC64_T */
#ifndef HAVE_ATOMIC64_CMPXCHG
#define atomic64_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
#endif
#ifndef HAVE_ATOMIC64_XCHG
#define atomic64_xchg(v, n) (xchg(&((v)->counter), n))
#endif
#endif /* _SPL_ATOMIC_COMPAT_H */
|