atomic_utils_arch.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2020 Otto-von-Guericke-Universität Magdeburg
3  * SPDX-FileCopyrightText: 2021 Gerson Fernando Budke
4  * SPDX-License-Identifier: LGPL-2.1-only
5  */
6 
7 #pragma once
8 
20 #ifndef DOXYGEN
21 
22 #include "periph_cpu.h"
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 /* clang provides no built-in atomic access to regular variables */
29 #ifndef __clang__
30 
31 #define HAS_ATOMIC_LOAD_U8
32 static inline uint8_t atomic_load_u8(const volatile uint8_t *var)
33 {
34  return __atomic_load_1(var, __ATOMIC_SEQ_CST);
35 }
36 
37 #define HAS_ATOMIC_STORE_U8
38 static inline void atomic_store_u8(volatile uint8_t *dest, uint8_t val)
39 {
40  __atomic_store_1(dest, val, __ATOMIC_SEQ_CST);
41 }
42 
43 #endif /* __clang__ */
44 
45 #ifdef __cplusplus
46 }
47 #endif
48 
49 #endif /* DOXYGEN */
static void atomic_store_u8(volatile uint8_t *dest, uint8_t val)
Store an uint8_t atomically.
static uint8_t atomic_load_u8(const volatile uint8_t *var)
Load an uint8_t atomically.