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
22#include "periph_cpu.h"
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28#ifndef DOXYGEN
29
30/* clang provides no built-in atomic access to regular variables */
31#ifndef __clang__
32
33#define HAS_ATOMIC_LOAD_U8
34static inline uint8_t atomic_load_u8(const volatile uint8_t *var)
35{
36 return __atomic_load_1(var, __ATOMIC_SEQ_CST);
37}
38
39#define HAS_ATOMIC_LOAD_U16
40static inline uint16_t atomic_load_u16(const volatile uint16_t *var)
41{
42 return __atomic_load_2(var, __ATOMIC_SEQ_CST);
43}
44
45#define HAS_ATOMIC_LOAD_U32
46static inline uint32_t atomic_load_u32(const volatile uint32_t *var)
47{
48 return __atomic_load_4(var, __ATOMIC_SEQ_CST);
49}
50
51#define HAS_ATOMIC_STORE_U8
52static inline void atomic_store_u8(volatile uint8_t *dest, uint8_t val)
53{
54 __atomic_store_1(dest, val, __ATOMIC_SEQ_CST);
55}
56
57#define HAS_ATOMIC_STORE_U16
58static inline void atomic_store_u16(volatile uint16_t *dest, uint16_t val)
59{
60 __atomic_store_2(dest, val, __ATOMIC_SEQ_CST);
61}
62
63#define HAS_ATOMIC_STORE_U32
64static inline void atomic_store_u32(volatile uint32_t *dest, uint32_t val)
65{
66 __atomic_store_4(dest, val, __ATOMIC_SEQ_CST);
67}
68
69#endif /* __clang__ */
70
71#endif /* DOXYGEN */
72
73#ifdef __cplusplus
74}
75#endif
76
77#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.