atomic_utils_arch.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2020 Otto-von-Guericke-Universität Magdeburg
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
18 #ifndef DOXYGEN
19 
20 #include "periph_cpu.h"
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 /* clang provides no built-in atomic access to regular variables */
27 #ifndef __clang__
28 
29 #define HAS_ATOMIC_LOAD_U8
30 static inline uint8_t atomic_load_u8(const volatile uint8_t *var)
31 {
32  return __atomic_load_1(var, __ATOMIC_SEQ_CST);
33 }
34 
35 #define HAS_ATOMIC_LOAD_U16
36 static inline uint16_t atomic_load_u16(const volatile uint16_t *var)
37 {
38  return __atomic_load_2(var, __ATOMIC_SEQ_CST);
39 }
40 
41 #define HAS_ATOMIC_LOAD_U32
42 static inline uint32_t atomic_load_u32(const volatile uint32_t *var)
43 {
44  return __atomic_load_4(var, __ATOMIC_SEQ_CST);
45 }
46 
47 #define HAS_ATOMIC_STORE_U8
48 static inline void atomic_store_u8(volatile uint8_t *dest, uint8_t val)
49 {
50  __atomic_store_1(dest, val, __ATOMIC_SEQ_CST);
51 }
52 
53 #define HAS_ATOMIC_STORE_U16
54 static inline void atomic_store_u16(volatile uint16_t *dest, uint16_t val)
55 {
56  __atomic_store_2(dest, val, __ATOMIC_SEQ_CST);
57 }
58 
59 #define HAS_ATOMIC_STORE_U32
60 static inline void atomic_store_u32(volatile uint32_t *dest, uint32_t val)
61 {
62  __atomic_store_4(dest, val, __ATOMIC_SEQ_CST);
63 }
64 
65 #endif /* __clang__ */
66 
67 #ifdef __cplusplus
68 }
69 #endif
70 
71 #endif /* DOXYGEN */
static void atomic_store_u8(volatile uint8_t *dest, uint8_t val)
Store an uint8_t atomically.
static uint32_t atomic_load_u32(const volatile uint32_t *var)
Load an uint32_t atomically.
static uint16_t atomic_load_u16(const volatile uint16_t *var)
Load an uint16_t atomically.
static uint8_t atomic_load_u8(const volatile uint8_t *var)
Load an uint8_t atomically.
static void atomic_store_u16(volatile uint16_t *dest, uint16_t val)
Store an uint16_t atomically.
static void atomic_store_u32(volatile uint32_t *dest, uint32_t val)
Store an uint32_t atomically.