L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
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
36#if __SIZEOF_LONG__ == 8
37
57L4_INLINE int
58l4util_cmpxchg64(volatile l4_uint64_t * dest,
59 l4_uint64_t cmp_val, l4_uint64_t new_val);
60
61#endif
62
76L4_INLINE int
77l4util_cmpxchg32(volatile l4_uint32_t * dest,
78 l4_uint32_t cmp_val, l4_uint32_t new_val);
79
93L4_INLINE int
94l4util_cmpxchg16(volatile l4_uint16_t * dest,
95 l4_uint16_t cmp_val, l4_uint16_t new_val);
96
110L4_INLINE int
111l4util_cmpxchg8(volatile l4_uint8_t * dest,
112 l4_uint8_t cmp_val, l4_uint8_t new_val);
113
127L4_INLINE int
128l4util_cmpxchg(volatile l4_umword_t * dest,
129 l4_umword_t cmp_val, l4_umword_t new_val);
130
141l4util_xchg32(volatile l4_uint32_t * dest, l4_uint32_t val);
142
153l4util_xchg16(volatile l4_uint16_t * dest, l4_uint16_t val);
154
165l4util_xchg8(volatile l4_uint8_t * dest, l4_uint8_t val);
166
177l4util_xchg(volatile l4_umword_t * dest, l4_umword_t val);
178
180
186L4_INLINE void
187l4util_add8(volatile l4_uint8_t *dest, l4_uint8_t val);
189L4_INLINE void
190l4util_add16(volatile l4_uint16_t *dest, l4_uint16_t val);
192L4_INLINE void
193l4util_add32(volatile l4_uint32_t *dest, l4_uint32_t val);
195L4_INLINE void
196l4util_sub8(volatile l4_uint8_t *dest, l4_uint8_t val);
198L4_INLINE void
199l4util_sub16(volatile l4_uint16_t *dest, l4_uint16_t val);
201L4_INLINE void
202l4util_sub32(volatile l4_uint32_t *dest, l4_uint32_t val);
204L4_INLINE void
205l4util_and8(volatile l4_uint8_t *dest, l4_uint8_t val);
207L4_INLINE void
208l4util_and16(volatile l4_uint16_t *dest, l4_uint16_t val);
210L4_INLINE void
211l4util_and32(volatile l4_uint32_t *dest, l4_uint32_t val);
213L4_INLINE void
214l4util_or8(volatile l4_uint8_t *dest, l4_uint8_t val);
216L4_INLINE void
217l4util_or16(volatile l4_uint16_t *dest, l4_uint16_t val);
219L4_INLINE void
220l4util_or32(volatile l4_uint32_t *dest, l4_uint32_t val);
222
224
232l4util_add8_res(volatile l4_uint8_t *dest, l4_uint8_t val);
235l4util_add16_res(volatile l4_uint16_t *dest, l4_uint16_t val);
238l4util_add32_res(volatile l4_uint32_t *dest, l4_uint32_t val);
241l4util_sub8_res(volatile l4_uint8_t *dest, l4_uint8_t val);
244l4util_sub16_res(volatile l4_uint16_t *dest, l4_uint16_t val);
247l4util_sub32_res(volatile l4_uint32_t *dest, l4_uint32_t val);
250l4util_and8_res(volatile l4_uint8_t *dest, l4_uint8_t val);
253l4util_and16_res(volatile l4_uint16_t *dest, l4_uint16_t val);
256l4util_and32_res(volatile l4_uint32_t *dest, l4_uint32_t val);
259l4util_or8_res(volatile l4_uint8_t *dest, l4_uint8_t val);
262l4util_or16_res(volatile l4_uint16_t *dest, l4_uint16_t val);
265l4util_or32_res(volatile l4_uint32_t *dest, l4_uint32_t val);
267
269
274L4_INLINE void
275l4util_inc8(volatile l4_uint8_t *dest);
277L4_INLINE void
278l4util_inc16(volatile l4_uint16_t *dest);
280L4_INLINE void
281l4util_inc32(volatile l4_uint32_t *dest);
283L4_INLINE void
284l4util_dec8(volatile l4_uint8_t *dest);
286L4_INLINE void
287l4util_dec16(volatile l4_uint16_t *dest);
289L4_INLINE void
290l4util_dec32(volatile l4_uint32_t *dest);
292
294
301l4util_inc8_res(volatile l4_uint8_t *dest);
304l4util_inc16_res(volatile l4_uint16_t *dest);
307l4util_inc32_res(volatile l4_uint32_t *dest);
310l4util_dec8_res(volatile l4_uint8_t *dest);
313l4util_dec16_res(volatile l4_uint16_t *dest);
316l4util_dec32_res(volatile l4_uint32_t *dest);
318
326L4_INLINE void
327l4util_atomic_add(volatile long *dest, long val);
328
335L4_INLINE void
336l4util_atomic_inc(volatile long *dest);
337
339
340/*****************
341 * IMPLEMENTAION *
342 *****************/
343
344#if __SIZEOF_LONG__ == 8
345
346L4_INLINE int
347l4util_cmpxchg64(volatile l4_uint64_t * dest,
348 l4_uint64_t cmp_val, l4_uint64_t new_val)
349{
350 return __atomic_compare_exchange_n(dest, &cmp_val, new_val, 0,
351 __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
352}
353
354#endif
355
356L4_INLINE int
358 l4_uint32_t cmp_val, l4_uint32_t new_val)
359{
360 return __atomic_compare_exchange_n(dest, &cmp_val, new_val, 0,
361 __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
362}
363
364L4_INLINE int
366 l4_uint16_t cmp_val, l4_uint16_t new_val)
367{
368 return __atomic_compare_exchange_n(dest, &cmp_val, new_val, 0,
369 __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
370}
371
372L4_INLINE int
374 l4_uint8_t cmp_val, l4_uint8_t new_val)
375{
376 return __atomic_compare_exchange_n(dest, &cmp_val, new_val, 0,
377 __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
378}
379
380L4_INLINE int
382 l4_umword_t cmp_val, l4_umword_t new_val)
383{
384 return __atomic_compare_exchange_n(dest, &cmp_val, new_val, 0,
385 __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
386}
387
390{
391 return __atomic_exchange_n(dest, val, __ATOMIC_SEQ_CST);
392}
393
396{
397 return __atomic_exchange_n(dest, val, __ATOMIC_SEQ_CST);
398}
399
401l4util_xchg8(volatile l4_uint8_t * dest, l4_uint8_t val)
402{
403 return __atomic_exchange_n(dest, val, __ATOMIC_SEQ_CST);
404}
405
408{
409 return __atomic_exchange_n(dest, val, __ATOMIC_SEQ_CST);
410}
411
412L4_INLINE void
413l4util_inc8(volatile l4_uint8_t *dest)
414{ __atomic_fetch_add(dest, 1, __ATOMIC_SEQ_CST); }
415
416L4_INLINE void
418{ __atomic_fetch_add(dest, 1, __ATOMIC_SEQ_CST); }
419
420L4_INLINE void
422{ __atomic_fetch_add(dest, 1, __ATOMIC_SEQ_CST); }
423
424L4_INLINE void
425l4util_atomic_inc(volatile long *dest)
426{ __atomic_fetch_add(dest, 1, __ATOMIC_SEQ_CST); }
427
428L4_INLINE void
429l4util_dec8(volatile l4_uint8_t *dest)
430{ __atomic_fetch_sub(dest, 1, __ATOMIC_SEQ_CST); }
431
432L4_INLINE void
434{ __atomic_fetch_sub(dest, 1, __ATOMIC_SEQ_CST); }
435
436L4_INLINE void
438{ __atomic_fetch_sub(dest, 1, __ATOMIC_SEQ_CST); }
439
440
443{ return __atomic_add_fetch(dest, 1, __ATOMIC_SEQ_CST); }
444
447{ return __atomic_add_fetch(dest, 1, __ATOMIC_SEQ_CST); }
448
451{ return __atomic_add_fetch(dest, 1, __ATOMIC_SEQ_CST); }
452
455{ return __atomic_sub_fetch(dest, 1, __ATOMIC_SEQ_CST); }
456
459{ return __atomic_sub_fetch(dest, 1, __ATOMIC_SEQ_CST); }
460
463{ return __atomic_sub_fetch(dest, 1, __ATOMIC_SEQ_CST); }
464
466l4util_dec_res(volatile l4_umword_t *dest)
467{ return __atomic_sub_fetch(dest, 1, __ATOMIC_SEQ_CST); }
468
469L4_INLINE void
471{ __atomic_fetch_add(dest, val, __ATOMIC_SEQ_CST); }
472
473L4_INLINE void
475{ __atomic_fetch_add(dest, val, __ATOMIC_SEQ_CST); }
476
477L4_INLINE void
479{ __atomic_fetch_add(dest, val, __ATOMIC_SEQ_CST); }
480
481L4_INLINE void
482l4util_atomic_add(volatile long *dest, long val)
483{ __atomic_fetch_add(dest, val, __ATOMIC_SEQ_CST); }
484
485L4_INLINE void
487{ __atomic_fetch_sub(dest, val, __ATOMIC_SEQ_CST); }
488
489L4_INLINE void
491{ __atomic_fetch_sub(dest, val, __ATOMIC_SEQ_CST); }
492
493L4_INLINE void
495{ __atomic_fetch_sub(dest, val, __ATOMIC_SEQ_CST); }
496
497L4_INLINE void
499{ __atomic_fetch_and(dest, val, __ATOMIC_SEQ_CST); }
500
501L4_INLINE void
503{ __atomic_fetch_and(dest, val, __ATOMIC_SEQ_CST); }
504
505L4_INLINE void
507{ __atomic_fetch_and(dest, val, __ATOMIC_SEQ_CST); }
508
509L4_INLINE void
510l4util_or8(volatile l4_uint8_t *dest, l4_uint8_t val)
511{ __atomic_fetch_or(dest, val, __ATOMIC_SEQ_CST); }
512
513L4_INLINE void
515{ __atomic_fetch_or(dest, val, __ATOMIC_SEQ_CST); }
516
517L4_INLINE void
519{ __atomic_fetch_or(dest, val, __ATOMIC_SEQ_CST); }
520
523{ return __atomic_add_fetch(dest, val, __ATOMIC_SEQ_CST); }
524
527{ return __atomic_add_fetch(dest, val, __ATOMIC_SEQ_CST); }
528
531{ return __atomic_add_fetch(dest, val, __ATOMIC_SEQ_CST); }
532
535{ return __atomic_sub_fetch(dest, val, __ATOMIC_SEQ_CST); }
536
539{ return __atomic_sub_fetch(dest, val, __ATOMIC_SEQ_CST); }
540
543{ return __atomic_sub_fetch(dest, val, __ATOMIC_SEQ_CST); }
544
547{ return __atomic_and_fetch(dest, val, __ATOMIC_SEQ_CST); }
548
551{ return __atomic_and_fetch(dest, val, __ATOMIC_SEQ_CST); }
552
555{ return __atomic_and_fetch(dest, val, __ATOMIC_SEQ_CST); }
556
559{ return __atomic_or_fetch(dest, val, __ATOMIC_SEQ_CST); }
560
563{ return __atomic_or_fetch(dest, val, __ATOMIC_SEQ_CST); }
564
567{ return __atomic_or_fetch(dest, val, __ATOMIC_SEQ_CST); }
568
569#endif /* ! __L4UTIL__INCLUDE__ATOMIC_H__ */
L4 compiler related defines.
unsigned long l4_umword_t
Unsigned machine word.
Definition l4int.h:51
unsigned char l4_uint8_t
Unsigned 8bit value.
Definition l4int.h:36
unsigned int l4_uint32_t
Unsigned 32bit value.
Definition l4int.h:40
unsigned short int l4_uint16_t
Unsigned 16bit value.
Definition l4int.h:38
unsigned long long l4_uint64_t
Unsigned 64bit value.
Definition l4int.h:42
#define L4_INLINE
L4 Inline function attribute.
Definition compiler.h:62
#define EXTERN_C_BEGIN
Start section with C types and functions.
Definition compiler.h:192
#define EXTERN_C_END
End section with C types and functions.
Definition compiler.h:193
l4_uint32_t l4util_inc32_res(volatile l4_uint32_t *dest)
Definition atomic.h:450
void l4util_inc32(volatile l4_uint32_t *dest)
Definition atomic.h:421
void l4util_atomic_add(volatile long *dest, long val)
Atomic add.
Definition atomic.h:482
void l4util_dec16(volatile l4_uint16_t *dest)
Definition atomic.h:433
void l4util_and32(volatile l4_uint32_t *dest, l4_uint32_t val)
Definition atomic.h:506
l4_uint32_t l4util_xchg32(volatile l4_uint32_t *dest, l4_uint32_t val)
Atomic exchange (32 bit version)
Definition atomic.h:389
l4_uint16_t l4util_or16_res(volatile l4_uint16_t *dest, l4_uint16_t val)
Definition atomic.h:562
l4_uint32_t l4util_add32_res(volatile l4_uint32_t *dest, l4_uint32_t val)
Definition atomic.h:530
l4_uint8_t l4util_xchg8(volatile l4_uint8_t *dest, l4_uint8_t val)
Atomic exchange (8 bit version)
Definition atomic.h:401
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:373
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:365
l4_uint32_t l4util_dec32_res(volatile l4_uint32_t *dest)
Definition atomic.h:462
l4_uint32_t l4util_and32_res(volatile l4_uint32_t *dest, l4_uint32_t val)
Definition atomic.h:554
void l4util_add8(volatile l4_uint8_t *dest, l4_uint8_t val)
Definition atomic.h:470
l4_uint8_t l4util_add8_res(volatile l4_uint8_t *dest, l4_uint8_t val)
Definition atomic.h:522
l4_uint8_t l4util_and8_res(volatile l4_uint8_t *dest, l4_uint8_t val)
Definition atomic.h:546
void l4util_or32(volatile l4_uint32_t *dest, l4_uint32_t val)
Definition atomic.h:518
void l4util_or16(volatile l4_uint16_t *dest, l4_uint16_t val)
Definition atomic.h:514
void l4util_inc8(volatile l4_uint8_t *dest)
Definition atomic.h:413
void l4util_sub16(volatile l4_uint16_t *dest, l4_uint16_t val)
Definition atomic.h:490
void l4util_add32(volatile l4_uint32_t *dest, l4_uint32_t val)
Definition atomic.h:478
l4_uint16_t l4util_xchg16(volatile l4_uint16_t *dest, l4_uint16_t val)
Atomic exchange (16 bit version)
Definition atomic.h:395
void l4util_dec32(volatile l4_uint32_t *dest)
Definition atomic.h:437
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:381
l4_umword_t l4util_xchg(volatile l4_umword_t *dest, l4_umword_t val)
Atomic exchange (machine wide fields)
Definition atomic.h:407
l4_uint16_t l4util_and16_res(volatile l4_uint16_t *dest, l4_uint16_t val)
Definition atomic.h:550
l4_uint16_t l4util_dec16_res(volatile l4_uint16_t *dest)
Definition atomic.h:458
void l4util_and8(volatile l4_uint8_t *dest, l4_uint8_t val)
Definition atomic.h:498
void l4util_or8(volatile l4_uint8_t *dest, l4_uint8_t val)
Definition atomic.h:510
l4_uint32_t l4util_or32_res(volatile l4_uint32_t *dest, l4_uint32_t val)
Definition atomic.h:566
void l4util_atomic_inc(volatile long *dest)
Atomic increment.
Definition atomic.h:425
void l4util_add16(volatile l4_uint16_t *dest, l4_uint16_t val)
Definition atomic.h:474
l4_uint8_t l4util_sub8_res(volatile l4_uint8_t *dest, l4_uint8_t val)
Definition atomic.h:534
void l4util_sub8(volatile l4_uint8_t *dest, l4_uint8_t val)
Definition atomic.h:486
l4_uint8_t l4util_inc8_res(volatile l4_uint8_t *dest)
Definition atomic.h:442
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:357
l4_uint16_t l4util_add16_res(volatile l4_uint16_t *dest, l4_uint16_t val)
Definition atomic.h:526
l4_uint16_t l4util_inc16_res(volatile l4_uint16_t *dest)
Definition atomic.h:446
void l4util_sub32(volatile l4_uint32_t *dest, l4_uint32_t val)
Definition atomic.h:494
l4_uint16_t l4util_sub16_res(volatile l4_uint16_t *dest, l4_uint16_t val)
Definition atomic.h:538
void l4util_inc16(volatile l4_uint16_t *dest)
Definition atomic.h:417
void l4util_dec8(volatile l4_uint8_t *dest)
Definition atomic.h:429
void l4util_and16(volatile l4_uint16_t *dest, l4_uint16_t val)
Definition atomic.h:502
l4_uint8_t l4util_dec8_res(volatile l4_uint8_t *dest)
Definition atomic.h:454
l4_uint8_t l4util_or8_res(volatile l4_uint8_t *dest, l4_uint8_t val)
Definition atomic.h:558
l4_uint32_t l4util_sub32_res(volatile l4_uint32_t *dest, l4_uint32_t val)
Definition atomic.h:542