Zephyr Project API 3.7.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
atomic_c.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 1997-2015, Wind River Systems, Inc.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef ZEPHYR_INCLUDE_SYS_ATOMIC_C_H_
8#define ZEPHYR_INCLUDE_SYS_ATOMIC_C_H_
9
10/* Included from <atomic.h> */
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
16/* Simple and correct (but very slow) implementation of atomic
17 * primitives that require nothing more than kernel interrupt locking.
18 */
19
20__syscall bool atomic_cas(atomic_t *target, atomic_val_t old_value,
21 atomic_val_t new_value);
22
23__syscall bool atomic_ptr_cas(atomic_ptr_t *target, atomic_ptr_val_t old_value,
24 atomic_ptr_val_t new_value);
25
26__syscall atomic_val_t atomic_add(atomic_t *target, atomic_val_t value);
27
28__syscall atomic_val_t atomic_sub(atomic_t *target, atomic_val_t value);
29
30static inline atomic_val_t atomic_inc(atomic_t *target)
31{
32 return atomic_add(target, 1);
33
34}
35
36static inline atomic_val_t atomic_dec(atomic_t *target)
37{
38 return atomic_sub(target, 1);
39
40}
41
43
45
46__syscall atomic_val_t atomic_set(atomic_t *target, atomic_val_t value);
47
49
50static inline atomic_val_t atomic_clear(atomic_t *target)
51{
52 return atomic_set(target, 0);
53
54}
55
57{
58 return atomic_ptr_set(target, NULL);
59
60}
61
62__syscall atomic_val_t atomic_or(atomic_t *target, atomic_val_t value);
63
64__syscall atomic_val_t atomic_xor(atomic_t *target, atomic_val_t value);
65
66__syscall atomic_val_t atomic_and(atomic_t *target, atomic_val_t value);
67
69
70#ifdef __cplusplus
71}
72#endif
73
74#ifdef CONFIG_ATOMIC_OPERATIONS_C
75
76#ifndef DISABLE_SYSCALL_TRACING
77/* Skip defining macros of atomic_*() for syscall tracing.
78 * Compiler does not like "({ ... tracing code ... })" and complains
79 *
80 * error: expected identifier or '(' before '{' token
81 *
82 * ... even though there is a '(' before '{'.
83 */
84#define DISABLE_SYSCALL_TRACING
85#define _REMOVE_DISABLE_SYSCALL_TRACING
86#endif
87
88#include <zephyr/syscalls/atomic_c.h>
89
90#ifdef _REMOVE_DISABLE_SYSCALL_TRACING
91#undef DISABLE_SYSCALL_TRACING
92#undef _REMOVE_DISABLE_SYSCALL_TRACING
93#endif
94
95#endif
96
97#endif /* ZEPHYR_INCLUDE_SYS_ATOMIC_C_H_ */
static atomic_val_t atomic_dec(atomic_t *target)
Definition atomic_c.h:36
atomic_val_t atomic_or(atomic_t *target, atomic_val_t value)
atomic_val_t atomic_xor(atomic_t *target, atomic_val_t value)
atomic_ptr_val_t atomic_ptr_get(const atomic_ptr_t *target)
atomic_val_t atomic_get(const atomic_t *target)
atomic_ptr_val_t atomic_ptr_set(atomic_ptr_t *target, atomic_ptr_val_t value)
atomic_val_t atomic_nand(atomic_t *target, atomic_val_t value)
static atomic_val_t atomic_clear(atomic_t *target)
Definition atomic_c.h:50
atomic_val_t atomic_and(atomic_t *target, atomic_val_t value)
atomic_val_t atomic_add(atomic_t *target, atomic_val_t value)
atomic_val_t atomic_set(atomic_t *target, atomic_val_t value)
static atomic_val_t atomic_inc(atomic_t *target)
Definition atomic_c.h:30
atomic_val_t atomic_sub(atomic_t *target, atomic_val_t value)
static atomic_ptr_val_t atomic_ptr_clear(atomic_ptr_t *target)
Definition atomic_c.h:56
bool atomic_ptr_cas(atomic_ptr_t *target, atomic_ptr_val_t old_value, atomic_ptr_val_t new_value)
bool atomic_cas(atomic_t *target, atomic_val_t old_value, atomic_val_t new_value)
long atomic_t
Definition atomic_types.h:15
atomic_t atomic_val_t
Definition atomic_types.h:16
atomic_ptr_t atomic_ptr_val_t
Definition atomic_types.h:18
void * atomic_ptr_t
Definition atomic_types.h:17