Loading...
Searching...
No Matches
atomic_utils_arch.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2020 Otto-von-Guericke-Universität Magdeburg
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser General
5 * Public License v2.1. See the file LICENSE in the top level directory for more
6 * details.
7 */
8
19#ifndef ATOMIC_UTILS_ARCH_H
20#define ATOMIC_UTILS_ARCH_H
21#ifndef DOXYGEN
22
23#include "periph_cpu.h"
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29/* clang provides no built-in atomic access to regular variables */
30#ifndef __clang__
31
32#define HAS_ATOMIC_LOAD_U8
33static inline uint8_t atomic_load_u8(const volatile uint8_t *var)
34{
35 return __atomic_load_1(var, __ATOMIC_SEQ_CST);
36}
37
38#define HAS_ATOMIC_LOAD_U16
39static inline uint16_t atomic_load_u16(const volatile uint16_t *var)
40{
41 return __atomic_load_2(var, __ATOMIC_SEQ_CST);
42}
43
44#define HAS_ATOMIC_STORE_U8
45static inline void atomic_store_u8(volatile uint8_t *dest, uint8_t val)
46{
47 __atomic_store_1(dest, val, __ATOMIC_SEQ_CST);
48}
49
50#define HAS_ATOMIC_STORE_U16
51static inline void atomic_store_u16(volatile uint16_t *dest, uint16_t val)
52{
53 __atomic_store_2(dest, val, __ATOMIC_SEQ_CST);
54}
55
56#endif /* __clang__ */
57
58#ifdef __cplusplus
59}
60#endif
61
62#endif /* DOXYGEN */
63#endif /* ATOMIC_UTILS_ARCH_H */
static void atomic_store_u8(volatile uint8_t *dest, uint8_t val)
Store an uint8_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.