diff options
Diffstat (limited to 'include/nvgpu/linux/atomic.h')
-rw-r--r-- | include/nvgpu/linux/atomic.h | 149 |
1 files changed, 149 insertions, 0 deletions
diff --git a/include/nvgpu/linux/atomic.h b/include/nvgpu/linux/atomic.h new file mode 100644 index 0000000..0734672 --- /dev/null +++ b/include/nvgpu/linux/atomic.h | |||
@@ -0,0 +1,149 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify it | ||
5 | * under the terms and conditions of the GNU General Public License, | ||
6 | * version 2, as published by the Free Software Foundation. | ||
7 | * | ||
8 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
11 | * more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | #ifndef __NVGPU_ATOMIC_LINUX_H__ | ||
17 | #define __NVGPU_ATOMIC_LINUX_H__ | ||
18 | |||
19 | #ifdef __KERNEL__ | ||
20 | #include <linux/atomic.h> | ||
21 | #endif | ||
22 | |||
23 | typedef struct nvgpu_atomic { | ||
24 | atomic_t atomic_var; | ||
25 | } nvgpu_atomic_t; | ||
26 | |||
27 | typedef struct nvgpu_atomic64 { | ||
28 | atomic64_t atomic_var; | ||
29 | } nvgpu_atomic64_t; | ||
30 | |||
31 | #define __nvgpu_atomic_init(i) { ATOMIC_INIT(i) } | ||
32 | #define __nvgpu_atomic64_init(i) { ATOMIC64_INIT(i) } | ||
33 | |||
34 | static inline void __nvgpu_atomic_set(nvgpu_atomic_t *v, int i) | ||
35 | { | ||
36 | atomic_set(&v->atomic_var, i); | ||
37 | } | ||
38 | |||
39 | static inline int __nvgpu_atomic_read(nvgpu_atomic_t *v) | ||
40 | { | ||
41 | return atomic_read(&v->atomic_var); | ||
42 | } | ||
43 | |||
44 | static inline void __nvgpu_atomic_inc(nvgpu_atomic_t *v) | ||
45 | { | ||
46 | atomic_inc(&v->atomic_var); | ||
47 | } | ||
48 | |||
49 | static inline int __nvgpu_atomic_inc_return(nvgpu_atomic_t *v) | ||
50 | { | ||
51 | return atomic_inc_return(&v->atomic_var); | ||
52 | } | ||
53 | |||
54 | static inline void __nvgpu_atomic_dec(nvgpu_atomic_t *v) | ||
55 | { | ||
56 | atomic_dec(&v->atomic_var); | ||
57 | } | ||
58 | |||
59 | static inline int __nvgpu_atomic_dec_return(nvgpu_atomic_t *v) | ||
60 | { | ||
61 | return atomic_dec_return(&v->atomic_var); | ||
62 | } | ||
63 | |||
64 | static inline int __nvgpu_atomic_cmpxchg(nvgpu_atomic_t *v, int old, int new) | ||
65 | { | ||
66 | return atomic_cmpxchg(&v->atomic_var, old, new); | ||
67 | } | ||
68 | |||
69 | static inline int __nvgpu_atomic_xchg(nvgpu_atomic_t *v, int new) | ||
70 | { | ||
71 | return atomic_xchg(&v->atomic_var, new); | ||
72 | } | ||
73 | |||
74 | static inline bool __nvgpu_atomic_inc_and_test(nvgpu_atomic_t *v) | ||
75 | { | ||
76 | return atomic_inc_and_test(&v->atomic_var); | ||
77 | } | ||
78 | |||
79 | static inline bool __nvgpu_atomic_dec_and_test(nvgpu_atomic_t *v) | ||
80 | { | ||
81 | return atomic_dec_and_test(&v->atomic_var); | ||
82 | } | ||
83 | |||
84 | static inline bool __nvgpu_atomic_sub_and_test(int i, nvgpu_atomic_t *v) | ||
85 | { | ||
86 | return atomic_sub_and_test(i, &v->atomic_var); | ||
87 | } | ||
88 | |||
89 | static inline int __nvgpu_atomic_add_return(int i, nvgpu_atomic_t *v) | ||
90 | { | ||
91 | return atomic_add_return(i, &v->atomic_var); | ||
92 | } | ||
93 | |||
94 | static inline int __nvgpu_atomic_add_unless(nvgpu_atomic_t *v, int a, int u) | ||
95 | { | ||
96 | return atomic_add_unless(&v->atomic_var, a, u); | ||
97 | } | ||
98 | |||
99 | static inline void __nvgpu_atomic64_set(nvgpu_atomic64_t *v, long i) | ||
100 | { | ||
101 | atomic64_set(&v->atomic_var, i); | ||
102 | } | ||
103 | |||
104 | static inline long __nvgpu_atomic64_read(nvgpu_atomic64_t *v) | ||
105 | { | ||
106 | return atomic64_read(&v->atomic_var); | ||
107 | } | ||
108 | |||
109 | static inline void __nvgpu_atomic64_add(long x, nvgpu_atomic64_t *v) | ||
110 | { | ||
111 | atomic64_add(x, &v->atomic_var); | ||
112 | } | ||
113 | |||
114 | static inline void __nvgpu_atomic64_inc(nvgpu_atomic64_t *v) | ||
115 | { | ||
116 | atomic64_inc(&v->atomic_var); | ||
117 | } | ||
118 | |||
119 | static inline long __nvgpu_atomic64_inc_return(nvgpu_atomic64_t *v) | ||
120 | { | ||
121 | return atomic64_inc_return(&v->atomic_var); | ||
122 | } | ||
123 | |||
124 | static inline void __nvgpu_atomic64_dec(nvgpu_atomic64_t *v) | ||
125 | { | ||
126 | atomic64_dec(&v->atomic_var); | ||
127 | } | ||
128 | |||
129 | static inline void __nvgpu_atomic64_dec_return(nvgpu_atomic64_t *v) | ||
130 | { | ||
131 | atomic64_dec_return(&v->atomic_var); | ||
132 | } | ||
133 | |||
134 | static inline long __nvgpu_atomic64_cmpxchg(nvgpu_atomic64_t *v, | ||
135 | long old, long new) | ||
136 | { | ||
137 | return atomic64_cmpxchg(&v->atomic_var, old, new); | ||
138 | } | ||
139 | |||
140 | static inline void __nvgpu_atomic64_sub(long x, nvgpu_atomic64_t *v) | ||
141 | { | ||
142 | atomic64_sub(x, &v->atomic_var); | ||
143 | } | ||
144 | |||
145 | static inline long __nvgpu_atomic64_sub_return(long x, nvgpu_atomic64_t *v) | ||
146 | { | ||
147 | return atomic64_sub_return(x, &v->atomic_var); | ||
148 | } | ||
149 | #endif /*__NVGPU_ATOMIC_LINUX_H__ */ | ||