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_LOAD_U32
45static inline uint32_t atomic_load_u32(const volatile uint32_t *var)
46{
47 return __atomic_load_4(var, __ATOMIC_SEQ_CST);
48}
49
50#define HAS_ATOMIC_STORE_U8
51static inline void atomic_store_u8(volatile uint8_t *dest, uint8_t val)
52{
53 __atomic_store_1(dest, val, __ATOMIC_SEQ_CST);
54}
55
56#define HAS_ATOMIC_STORE_U16
57static inline void atomic_store_u16(volatile uint16_t *dest, uint16_t val)
58{
59 __atomic_store_2(dest, val, __ATOMIC_SEQ_CST);
60}
61
62#define HAS_ATOMIC_STORE_U32
63static inline void atomic_store_u32(volatile uint32_t *dest, uint32_t val)
64{
65 __atomic_store_4(dest, val, __ATOMIC_SEQ_CST);
66}
67
68#endif /* __clang__ */
69
70#ifdef __cplusplus
71}
72#endif
73
74#endif /* DOXYGEN */
75#endif /* ATOMIC_UTILS_ARCH_H */
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.