]>
Commit | Line | Data |
---|---|---|
b0dd3380 | 1 | #ifndef _SPL_ATOMIC_H |
2 | #define _SPL_ATOMIC_H | |
3 | ||
4 | #ifdef __cplusplus | |
5 | extern "C" { | |
6 | #endif | |
7 | ||
8 | #include <linux/module.h> | |
9 | /* FIXME - NONE OF THIS IS ATOMIC, IT SHOULD BE. I think we can | |
10 | * get by for now since I'm only working on real 64bit systems but | |
11 | * this will need to be addressed properly. | |
12 | */ | |
13 | static __inline__ void | |
14 | atomic_inc_64(volatile uint64_t *target) | |
15 | { | |
16 | (*target)++; | |
17 | } | |
18 | ||
19 | static __inline__ void | |
20 | atomic_dec_64(volatile uint64_t *target) | |
21 | { | |
22 | (*target)--; | |
23 | } | |
24 | ||
25 | static __inline__ uint64_t | |
26 | atomic_add_64(volatile uint64_t *target, uint64_t delta) | |
27 | { | |
28 | uint64_t rc = *target; | |
29 | *target += delta; | |
30 | return rc; | |
31 | } | |
32 | ||
33 | static __inline__ uint64_t | |
34 | atomic_add_64_nv(volatile uint64_t *target, uint64_t delta) | |
35 | { | |
36 | *target += delta; | |
37 | return *target; | |
38 | } | |
39 | ||
40 | static __inline__ uint64_t | |
41 | atomic_cas_64(volatile uint64_t *target, uint64_t cmp, | |
42 | uint64_t newval) | |
43 | { | |
44 | uint64_t rc = *target; | |
45 | ||
46 | if (*target == cmp) | |
47 | *target = newval; | |
48 | ||
49 | return rc; | |
50 | } | |
51 | ||
52 | static __inline__ void * | |
53 | atomic_cas_ptr(volatile void *target, void *cmp, void *newval) | |
54 | { | |
55 | void *rc = (void *)target; | |
56 | ||
57 | if (target == cmp) | |
58 | target = newval; | |
59 | ||
60 | return rc; | |
61 | } | |
62 | ||
63 | #ifdef __cplusplus | |
64 | } | |
65 | #endif | |
66 | ||
67 | #endif /* _SPL_ATOMIC_H */ | |
68 |