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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/*
* Copyright (C) 2018 - 2024, Stephan Mueller <smueller@chronox.de>
*
* License: see COPYING file in root directory
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
* WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*/
/*
* Atomic operations only work on:
* GCC >= 4.1
* Clang / LLVM
*/
/**
* Atomic type and operations equivalent to the Linux kernel.
*/
typedef struct atomic_t;
/**
* Memory barrier
*/
static inline void
/**
* Read atomic variable
* @param v atomic variable
* @return variable content
*/
static inline int
/**
* Set atomic variable
* @param i value to be set
* @param v atomic variable
*/
static inline void
/**
* Atomic add operation
* @param i integer value to add
* @param v atomic variable
* @return variable content after operation
*/
static inline int
/**
* Atomic add value from variable and test for zero
* @param i integer value to add
* @param v atomic variable
* @return true if the result is zero, or false for all other cases.
*/
static inline int
/**
* Atomic increment by 1
* @param v atomic variable
* @return variable content after operation
*/
static inline int
/**
* Atomic increment and test for zero
* @param v pointer of type atomic_t
* @return true if the result is zero, or false for all other cases.
*/
static inline int
/**
* Atomic subtract operation
* @param i integer value to subtract
* @param v atomic variable
* @return variable content after operation
*/
static inline int
/**
* Atomic subtract value from variable and test for zero
* @param i integer value to subtract
* @param v atomic variable
* @return true if the result is zero, or false for all other cases.
*/
static inline int
/**
* Atomic decrement by 1
* @param v: atomic variable
* @return variable content after operation
*/
static inline int
/**
* Atomic decrement by 1 and test for zero
* @param v atomic variable
* @return true if the result is zero, or false for all other cases.
*/
static inline int
/**
* Atomic or operation
* @param i integer value to or
* @param v atomic variable
* @return variable content after operation
*/
static inline int
/**
* Atomic xor operation
* @param i integer value to xor
* @param v atomic variable
* @return variable content after operation
*/
static inline int
/**
* Atomic and operation
* @param i integer value to and
* @param v atomic variable
* @return variable content after operation
*/
static inline int
/**
* Atomic nand operation
* @param i integer value to nand
* @param v atomic variable
* @return variable content after operation
*/
static inline int
/**
* Atomic compare and exchange operation (if current value of atomic
* variable is equal to the old value, set the new value)
* @param v atomic variable
* @param old integer value to compare with
* @param new integer value to set atomic variable to
* @return true if comparison is successful and new was written
*/
static inline int