L4Re - L4 Runtime Environment
atomic.h
Go to the documentation of this file.
1 /*****************************************************************************/
10 /*
11  * (c) 2000-2009 Author(s)
12  * economic rights: Technische Universit├Ąt Dresden (Germany)
13  * This file is part of TUD:OS and distributed under the terms of the
14  * GNU Lesser General Public License 2.1.
15  * Please see the COPYING-LGPL-2.1 file for details.
16  */
17 
18 /*****************************************************************************/
19 #ifndef __L4UTIL__INCLUDE__ATOMIC_H__
20 #define __L4UTIL__INCLUDE__ATOMIC_H__
21 
22 #include <l4/sys/l4int.h>
23 #include <l4/sys/compiler.h>
24 
25 /*****************************************************************************
26  *** Prototypes
27  *****************************************************************************/
28 
30 
49 L4_INLINE int
50 l4util_cmpxchg64(volatile l4_uint64_t * dest,
51  l4_uint64_t cmp_val, l4_uint64_t new_val);
52 
66 L4_INLINE int
67 l4util_cmpxchg32(volatile l4_uint32_t * dest,
68  l4_uint32_t cmp_val, l4_uint32_t new_val);
69 
83 L4_INLINE int
84 l4util_cmpxchg16(volatile l4_uint16_t * dest,
85  l4_uint16_t cmp_val, l4_uint16_t new_val);
86 
100 L4_INLINE int
101 l4util_cmpxchg8(volatile l4_uint8_t * dest,
102  l4_uint8_t cmp_val, l4_uint8_t new_val);
103 
117 L4_INLINE int
118 l4util_cmpxchg(volatile l4_umword_t * dest,
119  l4_umword_t cmp_val, l4_umword_t new_val);
120 
130 L4_INLINE l4_uint32_t
131 l4util_xchg32(volatile l4_uint32_t * dest, l4_uint32_t val);
132 
142 L4_INLINE l4_uint16_t
143 l4util_xchg16(volatile l4_uint16_t * dest, l4_uint16_t val);
144 
154 L4_INLINE l4_uint8_t
155 l4util_xchg8(volatile l4_uint8_t * dest, l4_uint8_t val);
156 
166 L4_INLINE l4_umword_t
167 l4util_xchg(volatile l4_umword_t * dest, l4_umword_t val);
168 
170 
176 L4_INLINE void
177 l4util_add8(volatile l4_uint8_t *dest, l4_uint8_t val);
178 L4_INLINE void
179 l4util_add16(volatile l4_uint16_t *dest, l4_uint16_t val);
180 L4_INLINE void
181 l4util_add32(volatile l4_uint32_t *dest, l4_uint32_t val);
182 L4_INLINE void
183 l4util_sub8(volatile l4_uint8_t *dest, l4_uint8_t val);
184 L4_INLINE void
185 l4util_sub16(volatile l4_uint16_t *dest, l4_uint16_t val);
186 L4_INLINE void
187 l4util_sub32(volatile l4_uint32_t *dest, l4_uint32_t val);
188 L4_INLINE void
189 l4util_and8(volatile l4_uint8_t *dest, l4_uint8_t val);
190 L4_INLINE void
191 l4util_and16(volatile l4_uint16_t *dest, l4_uint16_t val);
192 L4_INLINE void
193 l4util_and32(volatile l4_uint32_t *dest, l4_uint32_t val);
194 L4_INLINE void
195 l4util_or8(volatile l4_uint8_t *dest, l4_uint8_t val);
196 L4_INLINE void
197 l4util_or16(volatile l4_uint16_t *dest, l4_uint16_t val);
198 L4_INLINE void
199 l4util_or32(volatile l4_uint32_t *dest, l4_uint32_t val);
201 
203 
210 L4_INLINE l4_uint8_t
211 l4util_add8_res(volatile l4_uint8_t *dest, l4_uint8_t val);
212 L4_INLINE l4_uint16_t
213 l4util_add16_res(volatile l4_uint16_t *dest, l4_uint16_t val);
214 L4_INLINE l4_uint32_t
215 l4util_add32_res(volatile l4_uint32_t *dest, l4_uint32_t val);
216 L4_INLINE l4_uint8_t
217 l4util_sub8_res(volatile l4_uint8_t *dest, l4_uint8_t val);
218 L4_INLINE l4_uint16_t
219 l4util_sub16_res(volatile l4_uint16_t *dest, l4_uint16_t val);
220 L4_INLINE l4_uint32_t
221 l4util_sub32_res(volatile l4_uint32_t *dest, l4_uint32_t val);
222 L4_INLINE l4_uint8_t
223 l4util_and8_res(volatile l4_uint8_t *dest, l4_uint8_t val);
224 L4_INLINE l4_uint16_t
225 l4util_and16_res(volatile l4_uint16_t *dest, l4_uint16_t val);
226 L4_INLINE l4_uint32_t
227 l4util_and32_res(volatile l4_uint32_t *dest, l4_uint32_t val);
228 L4_INLINE l4_uint8_t
229 l4util_or8_res(volatile l4_uint8_t *dest, l4_uint8_t val);
230 L4_INLINE l4_uint16_t
231 l4util_or16_res(volatile l4_uint16_t *dest, l4_uint16_t val);
232 L4_INLINE l4_uint32_t
233 l4util_or32_res(volatile l4_uint32_t *dest, l4_uint32_t val);
235 
237 
242 L4_INLINE void
243 l4util_inc8(volatile l4_uint8_t *dest);
244 L4_INLINE void
245 l4util_inc16(volatile l4_uint16_t *dest);
246 L4_INLINE void
247 l4util_inc32(volatile l4_uint32_t *dest);
248 L4_INLINE void
249 l4util_dec8(volatile l4_uint8_t *dest);
250 L4_INLINE void
251 l4util_dec16(volatile l4_uint16_t *dest);
252 L4_INLINE void
253 l4util_dec32(volatile l4_uint32_t *dest);
255 
257 
263 L4_INLINE l4_uint8_t
264 l4util_inc8_res(volatile l4_uint8_t *dest);
265 L4_INLINE l4_uint16_t
266 l4util_inc16_res(volatile l4_uint16_t *dest);
267 L4_INLINE l4_uint32_t
268 l4util_inc32_res(volatile l4_uint32_t *dest);
269 L4_INLINE l4_uint8_t
270 l4util_dec8_res(volatile l4_uint8_t *dest);
271 L4_INLINE l4_uint16_t
272 l4util_dec16_res(volatile l4_uint16_t *dest);
273 L4_INLINE l4_uint32_t
274 l4util_dec32_res(volatile l4_uint32_t *dest);
276 
284 L4_INLINE void
285 l4util_atomic_add(volatile long *dest, long val);
286 
293 L4_INLINE void
294 l4util_atomic_inc(volatile long *dest);
295 
297 
298 /*****************
299  * IMPLEMENTAION *
300  *****************/
301 
302 L4_INLINE int
304  l4_uint64_t cmp_val, l4_uint64_t new_val)
305 {
306  return __atomic_compare_exchange_n(dest, &cmp_val, new_val, 0,
307  __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
308 }
309 
310 L4_INLINE int
312  l4_uint32_t cmp_val, l4_uint32_t new_val)
313 {
314  return __atomic_compare_exchange_n(dest, &cmp_val, new_val, 0,
315  __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
316 }
317 
318 L4_INLINE int
320  l4_uint16_t cmp_val, l4_uint16_t new_val)
321 {
322  return __atomic_compare_exchange_n(dest, &cmp_val, new_val, 0,
323  __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
324 }
325 
326 L4_INLINE int
327 l4util_cmpxchg8(volatile l4_uint8_t * dest,
328  l4_uint8_t cmp_val, l4_uint8_t new_val)
329 {
330  return __atomic_compare_exchange_n(dest, &cmp_val, new_val, 0,
331  __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
332 }
333 
334 L4_INLINE int
335 l4util_cmpxchg(volatile l4_umword_t * dest,
336  l4_umword_t cmp_val, l4_umword_t new_val)
337 {
338  return __atomic_compare_exchange_n(dest, &cmp_val, new_val, 0,
339  __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
340 }
341 
342 L4_INLINE l4_uint32_t
343 l4util_xchg32(volatile l4_uint32_t * dest, l4_uint32_t val)
344 {
345  return __atomic_exchange_n(dest, val, __ATOMIC_SEQ_CST);
346 }
347 
348 L4_INLINE l4_uint16_t
349 l4util_xchg16(volatile l4_uint16_t * dest, l4_uint16_t val)
350 {
351  return __atomic_exchange_n(dest, val, __ATOMIC_SEQ_CST);
352 }
353 
354 L4_INLINE l4_uint8_t
355 l4util_xchg8(volatile l4_uint8_t * dest, l4_uint8_t val)
356 {
357  return __atomic_exchange_n(dest, val, __ATOMIC_SEQ_CST);
358 }
359 
360 L4_INLINE l4_umword_t
361 l4util_xchg(volatile l4_umword_t * dest, l4_umword_t val)
362 {
363  return __atomic_exchange_n(dest, val, __ATOMIC_SEQ_CST);
364 }
365 
366 L4_INLINE void
367 l4util_inc8(volatile l4_uint8_t *dest)
368 { __atomic_fetch_add(dest, 1, __ATOMIC_SEQ_CST); }
369 
370 L4_INLINE void
371 l4util_inc16(volatile l4_uint16_t *dest)
372 { __atomic_fetch_add(dest, 1, __ATOMIC_SEQ_CST); }
373 
374 L4_INLINE void
375 l4util_inc32(volatile l4_uint32_t *dest)
376 { __atomic_fetch_add(dest, 1, __ATOMIC_SEQ_CST); }
377 
378 L4_INLINE void
379 l4util_atomic_inc(volatile long *dest)
380 { __atomic_fetch_add(dest, 1, __ATOMIC_SEQ_CST); }
381 
382 L4_INLINE void
383 l4util_dec8(volatile l4_uint8_t *dest)
384 { __atomic_fetch_sub(dest, 1, __ATOMIC_SEQ_CST); }
385 
386 L4_INLINE void
387 l4util_dec16(volatile l4_uint16_t *dest)
388 { __atomic_fetch_sub(dest, 1, __ATOMIC_SEQ_CST); }
389 
390 L4_INLINE void
391 l4util_dec32(volatile l4_uint32_t *dest)
392 { __atomic_fetch_sub(dest, 1, __ATOMIC_SEQ_CST); }
393 
394 
395 L4_INLINE l4_uint8_t
397 { return __atomic_add_fetch(dest, 1, __ATOMIC_SEQ_CST); }
398 
399 L4_INLINE l4_uint16_t
400 l4util_inc16_res(volatile l4_uint16_t *dest)
401 { return __atomic_add_fetch(dest, 1, __ATOMIC_SEQ_CST); }
402 
403 L4_INLINE l4_uint32_t
404 l4util_inc32_res(volatile l4_uint32_t *dest)
405 { return __atomic_add_fetch(dest, 1, __ATOMIC_SEQ_CST); }
406 
407 L4_INLINE l4_uint8_t
408 l4util_dec8_res(volatile l4_uint8_t *dest)
409 { return __atomic_sub_fetch(dest, 1, __ATOMIC_SEQ_CST); }
410 
411 L4_INLINE l4_uint16_t
412 l4util_dec16_res(volatile l4_uint16_t *dest)
413 { return __atomic_sub_fetch(dest, 1, __ATOMIC_SEQ_CST); }
414 
415 L4_INLINE l4_uint32_t
416 l4util_dec32_res(volatile l4_uint32_t *dest)
417 { return __atomic_sub_fetch(dest, 1, __ATOMIC_SEQ_CST); }
418 
419 L4_INLINE l4_umword_t
420 l4util_dec_res(volatile l4_umword_t *dest)
421 { return __atomic_sub_fetch(dest, 1, __ATOMIC_SEQ_CST); }
422 
423 L4_INLINE void
424 l4util_add8(volatile l4_uint8_t *dest, l4_uint8_t val)
425 { __atomic_fetch_add(dest, val, __ATOMIC_SEQ_CST); }
426 
427 L4_INLINE void
428 l4util_add16(volatile l4_uint16_t *dest, l4_uint16_t val)
429 { __atomic_fetch_add(dest, val, __ATOMIC_SEQ_CST); }
430 
431 L4_INLINE void
432 l4util_add32(volatile l4_uint32_t *dest, l4_uint32_t val)
433 { __atomic_fetch_add(dest, val, __ATOMIC_SEQ_CST); }
434 
435 L4_INLINE void
436 l4util_atomic_add(volatile long *dest, long val)
437 { __atomic_fetch_add(dest, val, __ATOMIC_SEQ_CST); }
438 
439 L4_INLINE void
440 l4util_sub8(volatile l4_uint8_t *dest, l4_uint8_t val)
441 { __atomic_fetch_sub(dest, val, __ATOMIC_SEQ_CST); }
442 
443 L4_INLINE void
444 l4util_sub16(volatile l4_uint16_t *dest, l4_uint16_t val)
445 { __atomic_fetch_sub(dest, val, __ATOMIC_SEQ_CST); }
446 
447 L4_INLINE void
448 l4util_sub32(volatile l4_uint32_t *dest, l4_uint32_t val)
449 { __atomic_fetch_sub(dest, val, __ATOMIC_SEQ_CST); }
450 
451 L4_INLINE void
452 l4util_and8(volatile l4_uint8_t *dest, l4_uint8_t val)
453 { __atomic_fetch_and(dest, val, __ATOMIC_SEQ_CST); }
454 
455 L4_INLINE void
456 l4util_and16(volatile l4_uint16_t *dest, l4_uint16_t val)
457 { __atomic_fetch_and(dest, val, __ATOMIC_SEQ_CST); }
458 
459 L4_INLINE void
460 l4util_and32(volatile l4_uint32_t *dest, l4_uint32_t val)
461 { __atomic_fetch_and(dest, val, __ATOMIC_SEQ_CST); }
462 
463 L4_INLINE void
464 l4util_or8(volatile l4_uint8_t *dest, l4_uint8_t val)
465 { __atomic_fetch_or(dest, val, __ATOMIC_SEQ_CST); }
466 
467 L4_INLINE void
468 l4util_or16(volatile l4_uint16_t *dest, l4_uint16_t val)
469 { __atomic_fetch_or(dest, val, __ATOMIC_SEQ_CST); }
470 
471 L4_INLINE void
472 l4util_or32(volatile l4_uint32_t *dest, l4_uint32_t val)
473 { __atomic_fetch_or(dest, val, __ATOMIC_SEQ_CST); }
474 
475 L4_INLINE l4_uint8_t
477 { return __atomic_add_fetch(dest, val, __ATOMIC_SEQ_CST); }
478 
479 L4_INLINE l4_uint16_t
480 l4util_add16_res(volatile l4_uint16_t *dest, l4_uint16_t val)
481 { return __atomic_add_fetch(dest, val, __ATOMIC_SEQ_CST); }
482 
483 L4_INLINE l4_uint32_t
484 l4util_add32_res(volatile l4_uint32_t *dest, l4_uint32_t val)
485 { return __atomic_add_fetch(dest, val, __ATOMIC_SEQ_CST); }
486 
487 L4_INLINE l4_uint8_t
488 l4util_sub8_res(volatile l4_uint8_t *dest, l4_uint8_t val)
489 { return __atomic_sub_fetch(dest, val, __ATOMIC_SEQ_CST); }
490 
491 L4_INLINE l4_uint16_t
492 l4util_sub16_res(volatile l4_uint16_t *dest, l4_uint16_t val)
493 { return __atomic_sub_fetch(dest, val, __ATOMIC_SEQ_CST); }
494 
495 L4_INLINE l4_uint32_t
496 l4util_sub32_res(volatile l4_uint32_t *dest, l4_uint32_t val)
497 { return __atomic_sub_fetch(dest, val, __ATOMIC_SEQ_CST); }
498 
499 L4_INLINE l4_uint8_t
500 l4util_and8_res(volatile l4_uint8_t *dest, l4_uint8_t val)
501 { return __atomic_and_fetch(dest, val, __ATOMIC_SEQ_CST); }
502 
503 L4_INLINE l4_uint16_t
504 l4util_and16_res(volatile l4_uint16_t *dest, l4_uint16_t val)
505 { return __atomic_and_fetch(dest, val, __ATOMIC_SEQ_CST); }
506 
507 L4_INLINE l4_uint32_t
508 l4util_and32_res(volatile l4_uint32_t *dest, l4_uint32_t val)
509 { return __atomic_and_fetch(dest, val, __ATOMIC_SEQ_CST); }
510 
511 L4_INLINE l4_uint8_t
512 l4util_or8_res(volatile l4_uint8_t *dest, l4_uint8_t val)
513 { return __atomic_or_fetch(dest, val, __ATOMIC_SEQ_CST); }
514 
515 L4_INLINE l4_uint16_t
516 l4util_or16_res(volatile l4_uint16_t *dest, l4_uint16_t val)
517 { return __atomic_or_fetch(dest, val, __ATOMIC_SEQ_CST); }
518 
519 L4_INLINE l4_uint32_t
520 l4util_or32_res(volatile l4_uint32_t *dest, l4_uint32_t val)
521 { return __atomic_or_fetch(dest, val, __ATOMIC_SEQ_CST); }
522 
523 #endif /* ! __L4UTIL__INCLUDE__ATOMIC_H__ */
l4_umword_t l4util_xchg(volatile l4_umword_t *dest, l4_umword_t val)
Atomic exchange (machine wide fields)
Definition: atomic.h:361
l4_uint32_t l4util_xchg32(volatile l4_uint32_t *dest, l4_uint32_t val)
Atomic exchange (32 bit version)
Definition: atomic.h:343
unsigned short int l4_uint16_t
Unsigned 16bit value.
Definition: l4int.h:38
l4_uint8_t l4util_inc8_res(volatile l4_uint8_t *dest)
Definition: atomic.h:396
#define EXTERN_C_END
End section with C types and functions.
Definition: compiler.h:187
int l4util_cmpxchg64(volatile l4_uint64_t *dest, l4_uint64_t cmp_val, l4_uint64_t new_val)
Atomic compare and exchange (64 bit version)
Definition: atomic.h:303
int l4util_cmpxchg(volatile l4_umword_t *dest, l4_umword_t cmp_val, l4_umword_t new_val)
Atomic compare and exchange (machine wide fields)
Definition: atomic.h:335
L4 compiler related defines.
l4_uint16_t l4util_xchg16(volatile l4_uint16_t *dest, l4_uint16_t val)
Atomic exchange (16 bit version)
Definition: atomic.h:349
int l4util_cmpxchg32(volatile l4_uint32_t *dest, l4_uint32_t cmp_val, l4_uint32_t new_val)
Atomic compare and exchange (32 bit version)
Definition: atomic.h:311
int l4util_cmpxchg8(volatile l4_uint8_t *dest, l4_uint8_t cmp_val, l4_uint8_t new_val)
Atomic compare and exchange (8 bit version)
Definition: atomic.h:327
l4_uint8_t l4util_xchg8(volatile l4_uint8_t *dest, l4_uint8_t val)
Atomic exchange (8 bit version)
Definition: atomic.h:355
void l4util_atomic_inc(volatile long *dest)
Atomic increment.
Definition: atomic.h:379
unsigned long l4_umword_t
Unsigned machine word.
Definition: l4int.h:52
#define EXTERN_C_BEGIN
Start section with C types and functions.
Definition: compiler.h:186
void l4util_atomic_add(volatile long *dest, long val)
Atomic add.
Definition: atomic.h:436
unsigned char l4_uint8_t
Unsigned 8bit value.
Definition: l4int.h:36
int l4util_cmpxchg16(volatile l4_uint16_t *dest, l4_uint16_t cmp_val, l4_uint16_t new_val)
Atomic compare and exchange (16 bit version)
Definition: atomic.h:319
void l4util_inc8(volatile l4_uint8_t *dest)
Definition: atomic.h:367
unsigned long long l4_uint64_t
Unsigned 64bit value.
Definition: l4int.h:42
l4_uint8_t l4util_add8_res(volatile l4_uint8_t *dest, l4_uint8_t val)
Definition: atomic.h:476
unsigned int l4_uint32_t
Unsigned 32bit value.
Definition: l4int.h:40
void l4util_add8(volatile l4_uint8_t *dest, l4_uint8_t val)
Definition: atomic.h:424