Loading...
Searching...
No Matches
atomic.h
Go to the documentation of this file.
/*****************************************************************************/
/*
* (c) 2000-2009 Author(s)
* economic rights: Technische Universität Dresden (Germany)
* License: see LICENSE.spdx (in this directory or the directories above)
*/
/*****************************************************************************/
#ifndef __L4UTIL__INCLUDE__ATOMIC_H__
#define __L4UTIL__INCLUDE__ATOMIC_H__
#include <l4/sys/l4int.h>
#include <l4/sys/compiler.h>
/*****************************************************************************
*** Prototypes
*****************************************************************************/
L4_BEGIN_DECLS
#if __SIZEOF_LONG__ == 8
L4_INLINE int
l4util_cmpxchg64(volatile l4_uint64_t * dest,
l4_uint64_t cmp_val, l4_uint64_t new_val);
#endif
L4_INLINE int
l4util_cmpxchg32(volatile l4_uint32_t * dest,
l4_uint32_t cmp_val, l4_uint32_t new_val);
L4_INLINE int
l4util_cmpxchg16(volatile l4_uint16_t * dest,
l4_uint16_t cmp_val, l4_uint16_t new_val);
L4_INLINE int
l4util_cmpxchg8(volatile l4_uint8_t * dest,
l4_uint8_t cmp_val, l4_uint8_t new_val);
L4_INLINE int
l4util_cmpxchg(volatile l4_umword_t * dest,
l4_umword_t cmp_val, l4_umword_t new_val);
L4_INLINE l4_uint32_t
l4util_xchg32(volatile l4_uint32_t * dest, l4_uint32_t val);
L4_INLINE l4_uint16_t
l4util_xchg16(volatile l4_uint16_t * dest, l4_uint16_t val);
L4_INLINE l4_uint8_t
l4util_xchg8(volatile l4_uint8_t * dest, l4_uint8_t val);
L4_INLINE l4_umword_t
l4util_xchg(volatile l4_umword_t * dest, l4_umword_t val);
L4_INLINE void
l4util_add8(volatile l4_uint8_t *dest, l4_uint8_t val);
L4_INLINE void
l4util_add16(volatile l4_uint16_t *dest, l4_uint16_t val);
L4_INLINE void
l4util_add32(volatile l4_uint32_t *dest, l4_uint32_t val);
L4_INLINE void
l4util_sub8(volatile l4_uint8_t *dest, l4_uint8_t val);
L4_INLINE void
l4util_sub16(volatile l4_uint16_t *dest, l4_uint16_t val);
L4_INLINE void
l4util_sub32(volatile l4_uint32_t *dest, l4_uint32_t val);
L4_INLINE void
l4util_and8(volatile l4_uint8_t *dest, l4_uint8_t val);
L4_INLINE void
l4util_and16(volatile l4_uint16_t *dest, l4_uint16_t val);
L4_INLINE void
l4util_and32(volatile l4_uint32_t *dest, l4_uint32_t val);
L4_INLINE void
l4util_or8(volatile l4_uint8_t *dest, l4_uint8_t val);
L4_INLINE void
l4util_or16(volatile l4_uint16_t *dest, l4_uint16_t val);
L4_INLINE void
l4util_or32(volatile l4_uint32_t *dest, l4_uint32_t val);
L4_INLINE l4_uint8_t
l4util_add8_res(volatile l4_uint8_t *dest, l4_uint8_t val);
L4_INLINE l4_uint16_t
l4util_add16_res(volatile l4_uint16_t *dest, l4_uint16_t val);
L4_INLINE l4_uint32_t
l4util_add32_res(volatile l4_uint32_t *dest, l4_uint32_t val);
L4_INLINE l4_uint8_t
l4util_sub8_res(volatile l4_uint8_t *dest, l4_uint8_t val);
L4_INLINE l4_uint16_t
l4util_sub16_res(volatile l4_uint16_t *dest, l4_uint16_t val);
L4_INLINE l4_uint32_t
l4util_sub32_res(volatile l4_uint32_t *dest, l4_uint32_t val);
L4_INLINE l4_uint8_t
l4util_and8_res(volatile l4_uint8_t *dest, l4_uint8_t val);
L4_INLINE l4_uint16_t
l4util_and16_res(volatile l4_uint16_t *dest, l4_uint16_t val);
L4_INLINE l4_uint32_t
l4util_and32_res(volatile l4_uint32_t *dest, l4_uint32_t val);
L4_INLINE l4_uint8_t
l4util_or8_res(volatile l4_uint8_t *dest, l4_uint8_t val);
L4_INLINE l4_uint16_t
l4util_or16_res(volatile l4_uint16_t *dest, l4_uint16_t val);
L4_INLINE l4_uint32_t
l4util_or32_res(volatile l4_uint32_t *dest, l4_uint32_t val);
L4_INLINE void
l4util_inc8(volatile l4_uint8_t *dest);
L4_INLINE void
l4util_inc16(volatile l4_uint16_t *dest);
L4_INLINE void
l4util_inc32(volatile l4_uint32_t *dest);
L4_INLINE void
l4util_dec8(volatile l4_uint8_t *dest);
L4_INLINE void
l4util_dec16(volatile l4_uint16_t *dest);
L4_INLINE void
l4util_dec32(volatile l4_uint32_t *dest);
L4_INLINE l4_uint8_t
l4util_inc8_res(volatile l4_uint8_t *dest);
L4_INLINE l4_uint16_t
l4util_inc16_res(volatile l4_uint16_t *dest);
L4_INLINE l4_uint32_t
l4util_inc32_res(volatile l4_uint32_t *dest);
L4_INLINE l4_uint8_t
l4util_dec8_res(volatile l4_uint8_t *dest);
L4_INLINE l4_uint16_t
l4util_dec16_res(volatile l4_uint16_t *dest);
L4_INLINE l4_uint32_t
l4util_dec32_res(volatile l4_uint32_t *dest);
L4_INLINE void
l4util_atomic_add(volatile long *dest, long val);
L4_INLINE void
l4util_atomic_inc(volatile long *dest);
L4_END_DECLS
/*****************
* IMPLEMENTAION *
*****************/
#if __SIZEOF_LONG__ == 8
L4_INLINE int
l4util_cmpxchg64(volatile l4_uint64_t * dest,
l4_uint64_t cmp_val, l4_uint64_t new_val)
{
return __atomic_compare_exchange_n(dest, &cmp_val, new_val, 0,
__ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
}
#endif
L4_INLINE int
l4util_cmpxchg32(volatile l4_uint32_t * dest,
l4_uint32_t cmp_val, l4_uint32_t new_val)
{
return __atomic_compare_exchange_n(dest, &cmp_val, new_val, 0,
__ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
}
L4_INLINE int
l4util_cmpxchg16(volatile l4_uint16_t * dest,
l4_uint16_t cmp_val, l4_uint16_t new_val)
{
return __atomic_compare_exchange_n(dest, &cmp_val, new_val, 0,
__ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
}
L4_INLINE int
l4util_cmpxchg8(volatile l4_uint8_t * dest,
l4_uint8_t cmp_val, l4_uint8_t new_val)
{
return __atomic_compare_exchange_n(dest, &cmp_val, new_val, 0,
__ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
}
L4_INLINE int
l4util_cmpxchg(volatile l4_umword_t * dest,
l4_umword_t cmp_val, l4_umword_t new_val)
{
return __atomic_compare_exchange_n(dest, &cmp_val, new_val, 0,
__ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
}
L4_INLINE l4_uint32_t
l4util_xchg32(volatile l4_uint32_t * dest, l4_uint32_t val)
{
return __atomic_exchange_n(dest, val, __ATOMIC_SEQ_CST);
}
L4_INLINE l4_uint16_t
l4util_xchg16(volatile l4_uint16_t * dest, l4_uint16_t val)
{
return __atomic_exchange_n(dest, val, __ATOMIC_SEQ_CST);
}
L4_INLINE l4_uint8_t
l4util_xchg8(volatile l4_uint8_t * dest, l4_uint8_t val)
{
return __atomic_exchange_n(dest, val, __ATOMIC_SEQ_CST);
}
L4_INLINE l4_umword_t
l4util_xchg(volatile l4_umword_t * dest, l4_umword_t val)
{
return __atomic_exchange_n(dest, val, __ATOMIC_SEQ_CST);
}
L4_INLINE void
l4util_inc8(volatile l4_uint8_t *dest)
{ __atomic_fetch_add(dest, 1, __ATOMIC_SEQ_CST); }
L4_INLINE void
l4util_inc16(volatile l4_uint16_t *dest)
{ __atomic_fetch_add(dest, 1, __ATOMIC_SEQ_CST); }
L4_INLINE void
l4util_inc32(volatile l4_uint32_t *dest)
{ __atomic_fetch_add(dest, 1, __ATOMIC_SEQ_CST); }
L4_INLINE void
l4util_atomic_inc(volatile long *dest)
{ __atomic_fetch_add(dest, 1, __ATOMIC_SEQ_CST); }
L4_INLINE void
l4util_dec8(volatile l4_uint8_t *dest)
{ __atomic_fetch_sub(dest, 1, __ATOMIC_SEQ_CST); }
L4_INLINE void
l4util_dec16(volatile l4_uint16_t *dest)
{ __atomic_fetch_sub(dest, 1, __ATOMIC_SEQ_CST); }
L4_INLINE void
l4util_dec32(volatile l4_uint32_t *dest)
{ __atomic_fetch_sub(dest, 1, __ATOMIC_SEQ_CST); }
L4_INLINE l4_uint8_t
l4util_inc8_res(volatile l4_uint8_t *dest)
{ return __atomic_add_fetch(dest, 1, __ATOMIC_SEQ_CST); }
L4_INLINE l4_uint16_t
l4util_inc16_res(volatile l4_uint16_t *dest)
{ return __atomic_add_fetch(dest, 1, __ATOMIC_SEQ_CST); }
L4_INLINE l4_uint32_t
l4util_inc32_res(volatile l4_uint32_t *dest)
{ return __atomic_add_fetch(dest, 1, __ATOMIC_SEQ_CST); }
L4_INLINE l4_uint8_t
l4util_dec8_res(volatile l4_uint8_t *dest)
{ return __atomic_sub_fetch(dest, 1, __ATOMIC_SEQ_CST); }
L4_INLINE l4_uint16_t
l4util_dec16_res(volatile l4_uint16_t *dest)
{ return __atomic_sub_fetch(dest, 1, __ATOMIC_SEQ_CST); }
L4_INLINE l4_uint32_t
l4util_dec32_res(volatile l4_uint32_t *dest)
{ return __atomic_sub_fetch(dest, 1, __ATOMIC_SEQ_CST); }
L4_INLINE l4_umword_t
l4util_dec_res(volatile l4_umword_t *dest)
{ return __atomic_sub_fetch(dest, 1, __ATOMIC_SEQ_CST); }
L4_INLINE void
l4util_add8(volatile l4_uint8_t *dest, l4_uint8_t val)
{ __atomic_fetch_add(dest, val, __ATOMIC_SEQ_CST); }
L4_INLINE void
l4util_add16(volatile l4_uint16_t *dest, l4_uint16_t val)
{ __atomic_fetch_add(dest, val, __ATOMIC_SEQ_CST); }
L4_INLINE void
l4util_add32(volatile l4_uint32_t *dest, l4_uint32_t val)
{ __atomic_fetch_add(dest, val, __ATOMIC_SEQ_CST); }
L4_INLINE void
l4util_atomic_add(volatile long *dest, long val)
{ __atomic_fetch_add(dest, val, __ATOMIC_SEQ_CST); }
L4_INLINE void
l4util_sub8(volatile l4_uint8_t *dest, l4_uint8_t val)
{ __atomic_fetch_sub(dest, val, __ATOMIC_SEQ_CST); }
L4_INLINE void
l4util_sub16(volatile l4_uint16_t *dest, l4_uint16_t val)
{ __atomic_fetch_sub(dest, val, __ATOMIC_SEQ_CST); }
L4_INLINE void
l4util_sub32(volatile l4_uint32_t *dest, l4_uint32_t val)
{ __atomic_fetch_sub(dest, val, __ATOMIC_SEQ_CST); }
L4_INLINE void
l4util_and8(volatile l4_uint8_t *dest, l4_uint8_t val)
{ __atomic_fetch_and(dest, val, __ATOMIC_SEQ_CST); }
L4_INLINE void
l4util_and16(volatile l4_uint16_t *dest, l4_uint16_t val)
{ __atomic_fetch_and(dest, val, __ATOMIC_SEQ_CST); }
L4_INLINE void
l4util_and32(volatile l4_uint32_t *dest, l4_uint32_t val)
{ __atomic_fetch_and(dest, val, __ATOMIC_SEQ_CST); }
L4_INLINE void
l4util_or8(volatile l4_uint8_t *dest, l4_uint8_t val)
{ __atomic_fetch_or(dest, val, __ATOMIC_SEQ_CST); }
L4_INLINE void
l4util_or16(volatile l4_uint16_t *dest, l4_uint16_t val)
{ __atomic_fetch_or(dest, val, __ATOMIC_SEQ_CST); }
L4_INLINE void
l4util_or32(volatile l4_uint32_t *dest, l4_uint32_t val)
{ __atomic_fetch_or(dest, val, __ATOMIC_SEQ_CST); }
L4_INLINE l4_uint8_t
l4util_add8_res(volatile l4_uint8_t *dest, l4_uint8_t val)
{ return __atomic_add_fetch(dest, val, __ATOMIC_SEQ_CST); }
L4_INLINE l4_uint16_t
l4util_add16_res(volatile l4_uint16_t *dest, l4_uint16_t val)
{ return __atomic_add_fetch(dest, val, __ATOMIC_SEQ_CST); }
L4_INLINE l4_uint32_t
l4util_add32_res(volatile l4_uint32_t *dest, l4_uint32_t val)
{ return __atomic_add_fetch(dest, val, __ATOMIC_SEQ_CST); }
L4_INLINE l4_uint8_t
l4util_sub8_res(volatile l4_uint8_t *dest, l4_uint8_t val)
{ return __atomic_sub_fetch(dest, val, __ATOMIC_SEQ_CST); }
L4_INLINE l4_uint16_t
l4util_sub16_res(volatile l4_uint16_t *dest, l4_uint16_t val)
{ return __atomic_sub_fetch(dest, val, __ATOMIC_SEQ_CST); }
L4_INLINE l4_uint32_t
l4util_sub32_res(volatile l4_uint32_t *dest, l4_uint32_t val)
{ return __atomic_sub_fetch(dest, val, __ATOMIC_SEQ_CST); }
L4_INLINE l4_uint8_t
l4util_and8_res(volatile l4_uint8_t *dest, l4_uint8_t val)
{ return __atomic_and_fetch(dest, val, __ATOMIC_SEQ_CST); }
L4_INLINE l4_uint16_t
l4util_and16_res(volatile l4_uint16_t *dest, l4_uint16_t val)
{ return __atomic_and_fetch(dest, val, __ATOMIC_SEQ_CST); }
L4_INLINE l4_uint32_t
l4util_and32_res(volatile l4_uint32_t *dest, l4_uint32_t val)
{ return __atomic_and_fetch(dest, val, __ATOMIC_SEQ_CST); }
L4_INLINE l4_uint8_t
l4util_or8_res(volatile l4_uint8_t *dest, l4_uint8_t val)
{ return __atomic_or_fetch(dest, val, __ATOMIC_SEQ_CST); }
L4_INLINE l4_uint16_t
l4util_or16_res(volatile l4_uint16_t *dest, l4_uint16_t val)
{ return __atomic_or_fetch(dest, val, __ATOMIC_SEQ_CST); }
L4_INLINE l4_uint32_t
l4util_or32_res(volatile l4_uint32_t *dest, l4_uint32_t val)
{ return __atomic_or_fetch(dest, val, __ATOMIC_SEQ_CST); }
#endif /* ! __L4UTIL__INCLUDE__ATOMIC_H__ */
compiler.h
L4 compiler related defines.
l4_umword_t
unsigned long l4_umword_t
Unsigned machine word.
Definition l4int.h:40
l4_uint8_t
unsigned char l4_uint8_t
Unsigned 8bit value.
Definition l4int.h:25
l4_uint32_t
unsigned int l4_uint32_t
Unsigned 32bit value.
Definition l4int.h:29
l4_uint16_t
unsigned short int l4_uint16_t
Unsigned 16bit value.
Definition l4int.h:27
l4_uint64_t
unsigned long long l4_uint64_t
Unsigned 64bit value.
Definition l4int.h:31
L4_INLINE
#define L4_INLINE
L4 Inline function attribute.
Definition compiler.h:51
L4_BEGIN_DECLS
#define L4_BEGIN_DECLS
Start section with C types and functions.
Definition compiler.h:165
L4_END_DECLS
#define L4_END_DECLS
End section with C types and functions.
Definition compiler.h:166
l4util_inc32_res
l4_uint32_t l4util_inc32_res(volatile l4_uint32_t *dest)
Definition atomic.h:448
l4util_inc32
void l4util_inc32(volatile l4_uint32_t *dest)
Definition atomic.h:419
l4util_atomic_add
void l4util_atomic_add(volatile long *dest, long val)
Atomic add.
Definition atomic.h:480
l4util_dec16
void l4util_dec16(volatile l4_uint16_t *dest)
Definition atomic.h:431
l4util_and32
void l4util_and32(volatile l4_uint32_t *dest, l4_uint32_t val)
Definition atomic.h:504
l4util_xchg32
l4_uint32_t l4util_xchg32(volatile l4_uint32_t *dest, l4_uint32_t val)
Atomic exchange (32 bit version).
Definition atomic.h:387
l4util_or16_res
l4_uint16_t l4util_or16_res(volatile l4_uint16_t *dest, l4_uint16_t val)
Definition atomic.h:560
l4util_add32_res
l4_uint32_t l4util_add32_res(volatile l4_uint32_t *dest, l4_uint32_t val)
Definition atomic.h:528
l4util_xchg8
l4_uint8_t l4util_xchg8(volatile l4_uint8_t *dest, l4_uint8_t val)
Atomic exchange (8 bit version).
Definition atomic.h:399
l4util_cmpxchg8
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:371
l4util_cmpxchg16
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:363
l4util_dec32_res
l4_uint32_t l4util_dec32_res(volatile l4_uint32_t *dest)
Definition atomic.h:460
l4util_and32_res
l4_uint32_t l4util_and32_res(volatile l4_uint32_t *dest, l4_uint32_t val)
Definition atomic.h:552
l4util_add8
void l4util_add8(volatile l4_uint8_t *dest, l4_uint8_t val)
Definition atomic.h:468
l4util_add8_res
l4_uint8_t l4util_add8_res(volatile l4_uint8_t *dest, l4_uint8_t val)
Definition atomic.h:520
l4util_and8_res
l4_uint8_t l4util_and8_res(volatile l4_uint8_t *dest, l4_uint8_t val)
Definition atomic.h:544
l4util_or32
void l4util_or32(volatile l4_uint32_t *dest, l4_uint32_t val)
Definition atomic.h:516
l4util_or16
void l4util_or16(volatile l4_uint16_t *dest, l4_uint16_t val)
Definition atomic.h:512
l4util_inc8
void l4util_inc8(volatile l4_uint8_t *dest)
Definition atomic.h:411
l4util_sub16
void l4util_sub16(volatile l4_uint16_t *dest, l4_uint16_t val)
Definition atomic.h:488
l4util_add32
void l4util_add32(volatile l4_uint32_t *dest, l4_uint32_t val)
Definition atomic.h:476
l4util_xchg16
l4_uint16_t l4util_xchg16(volatile l4_uint16_t *dest, l4_uint16_t val)
Atomic exchange (16 bit version).
Definition atomic.h:393
l4util_dec32
void l4util_dec32(volatile l4_uint32_t *dest)
Definition atomic.h:435
l4util_cmpxchg32
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:355
l4util_cmpxchg
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:379
l4util_xchg
l4_umword_t l4util_xchg(volatile l4_umword_t *dest, l4_umword_t val)
Atomic exchange (machine wide fields).
Definition atomic.h:405
l4util_and16_res
l4_uint16_t l4util_and16_res(volatile l4_uint16_t *dest, l4_uint16_t val)
Definition atomic.h:548
l4util_dec16_res
l4_uint16_t l4util_dec16_res(volatile l4_uint16_t *dest)
Definition atomic.h:456
l4util_and8
void l4util_and8(volatile l4_uint8_t *dest, l4_uint8_t val)
Definition atomic.h:496
l4util_or8
void l4util_or8(volatile l4_uint8_t *dest, l4_uint8_t val)
Definition atomic.h:508
l4util_or32_res
l4_uint32_t l4util_or32_res(volatile l4_uint32_t *dest, l4_uint32_t val)
Definition atomic.h:564
l4util_atomic_inc
void l4util_atomic_inc(volatile long *dest)
Atomic increment.
Definition atomic.h:423
l4util_add16
void l4util_add16(volatile l4_uint16_t *dest, l4_uint16_t val)
Definition atomic.h:472
l4util_sub8_res
l4_uint8_t l4util_sub8_res(volatile l4_uint8_t *dest, l4_uint8_t val)
Definition atomic.h:532
l4util_sub8
void l4util_sub8(volatile l4_uint8_t *dest, l4_uint8_t val)
Definition atomic.h:484
l4util_inc8_res
l4_uint8_t l4util_inc8_res(volatile l4_uint8_t *dest)
Definition atomic.h:440
l4util_add16_res
l4_uint16_t l4util_add16_res(volatile l4_uint16_t *dest, l4_uint16_t val)
Definition atomic.h:524
l4util_inc16_res
l4_uint16_t l4util_inc16_res(volatile l4_uint16_t *dest)
Definition atomic.h:444
l4util_sub32
void l4util_sub32(volatile l4_uint32_t *dest, l4_uint32_t val)
Definition atomic.h:492
l4util_sub16_res
l4_uint16_t l4util_sub16_res(volatile l4_uint16_t *dest, l4_uint16_t val)
Definition atomic.h:536
l4util_inc16
void l4util_inc16(volatile l4_uint16_t *dest)
Definition atomic.h:415
l4util_dec8
void l4util_dec8(volatile l4_uint8_t *dest)
Definition atomic.h:427
l4util_and16
void l4util_and16(volatile l4_uint16_t *dest, l4_uint16_t val)
Definition atomic.h:500
l4util_dec8_res
l4_uint8_t l4util_dec8_res(volatile l4_uint8_t *dest)
Definition atomic.h:452
l4util_or8_res
l4_uint8_t l4util_or8_res(volatile l4_uint8_t *dest, l4_uint8_t val)
Definition atomic.h:556
l4util_sub32_res
l4_uint32_t l4util_sub32_res(volatile l4_uint32_t *dest, l4_uint32_t val)
Definition atomic.h:540
l4int.h
Fixed sized integer types, generic version.