Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
atomic_builtin.h
Go to the documentation of this file.
1/* atomic operations */
2
3/*
4 * Copyright (c) 1997-2015, Wind River Systems, Inc.
5 *
6 * SPDX-License-Identifier: Apache-2.0
7 */
8
9#ifndef ZEPHYR_INCLUDE_SYS_ATOMIC_BUILTIN_H_
10#define ZEPHYR_INCLUDE_SYS_ATOMIC_BUILTIN_H_
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
16/* Included from <atomic.h> */
17
37static inline bool atomic_cas(atomic_t *target, atomic_val_t old_value,
38 atomic_val_t new_value)
39{
40 return __atomic_compare_exchange_n(target, &old_value, new_value,
41 0, __ATOMIC_SEQ_CST,
42 __ATOMIC_SEQ_CST);
43}
44
58static inline bool atomic_ptr_cas(atomic_ptr_t *target, atomic_ptr_val_t old_value,
59 atomic_ptr_val_t new_value)
60{
61 return __atomic_compare_exchange_n(target, &old_value, new_value,
62 0, __ATOMIC_SEQ_CST,
63 __ATOMIC_SEQ_CST);
64}
65
78{
79 return __atomic_fetch_add(target, value, __ATOMIC_SEQ_CST);
80}
81
94{
95 return __atomic_fetch_sub(target, value, __ATOMIC_SEQ_CST);
96}
97
109{
110 return atomic_add(target, 1);
111}
112
124{
125 return atomic_sub(target, 1);
126}
127
139{
140 return __atomic_load_n(target, __ATOMIC_SEQ_CST);
141}
142
154{
155 return __atomic_load_n(target, __ATOMIC_SEQ_CST);
156}
157
171{
172 /* This builtin, as described by Intel, is not a traditional
173 * test-and-set operation, but rather an atomic exchange operation. It
174 * writes value into *ptr, and returns the previous contents of *ptr.
175 */
176 return __atomic_exchange_n(target, value, __ATOMIC_SEQ_CST);
177}
178
192{
193 return __atomic_exchange_n(target, value, __ATOMIC_SEQ_CST);
194}
195
208{
209 return atomic_set(target, 0);
210}
211
224{
225 return atomic_ptr_set(target, NULL);
226}
227
241{
242 return __atomic_fetch_or(target, value, __ATOMIC_SEQ_CST);
243}
244
258{
259 return __atomic_fetch_xor(target, value, __ATOMIC_SEQ_CST);
260}
261
275{
276 return __atomic_fetch_and(target, value, __ATOMIC_SEQ_CST);
277}
278
292{
293 return __atomic_fetch_nand(target, value, __ATOMIC_SEQ_CST);
294}
295
299#ifdef __cplusplus
300}
301#endif
302
303#endif /* ZEPHYR_INCLUDE_SYS_ATOMIC_BUILTIN_H_ */
atomic_t atomic_val_t
Definition: atomic.h:22
atomic_ptr_t atomic_ptr_val_t
Definition: atomic.h:24
void * atomic_ptr_t
Definition: atomic.h:23
int atomic_t
Definition: atomic.h:21
static atomic_val_t atomic_dec(atomic_t *target)
Atomic decrement.
Definition: atomic_builtin.h:123
static atomic_val_t atomic_sub(atomic_t *target, atomic_val_t value)
Atomic subtraction.
Definition: atomic_builtin.h:93
static atomic_val_t atomic_xor(atomic_t *target, atomic_val_t value)
Atomic bitwise exclusive OR (XOR).
Definition: atomic_builtin.h:257
static bool atomic_ptr_cas(atomic_ptr_t *target, atomic_ptr_val_t old_value, atomic_ptr_val_t new_value)
Atomic compare-and-set with pointer values.
Definition: atomic_builtin.h:58
static atomic_val_t atomic_clear(atomic_t *target)
Atomic clear.
Definition: atomic_builtin.h:207
static atomic_val_t atomic_set(atomic_t *target, atomic_val_t value)
Atomic get-and-set.
Definition: atomic_builtin.h:170
static atomic_val_t atomic_inc(atomic_t *target)
Atomic increment.
Definition: atomic_builtin.h:108
static bool atomic_cas(atomic_t *target, atomic_val_t old_value, atomic_val_t new_value)
Atomic compare-and-set.
Definition: atomic_builtin.h:37
static atomic_ptr_val_t atomic_ptr_clear(atomic_ptr_t *target)
Atomic clear of a pointer value.
Definition: atomic_builtin.h:223
static atomic_ptr_val_t atomic_ptr_get(const atomic_ptr_t *target)
Atomic get a pointer value.
Definition: atomic_builtin.h:153
static atomic_val_t atomic_nand(atomic_t *target, atomic_val_t value)
Atomic bitwise NAND.
Definition: atomic_builtin.h:291
static atomic_ptr_val_t atomic_ptr_set(atomic_ptr_t *target, atomic_ptr_val_t value)
Atomic get-and-set for pointer values.
Definition: atomic_builtin.h:191
static atomic_val_t atomic_or(atomic_t *target, atomic_val_t value)
Atomic bitwise inclusive OR.
Definition: atomic_builtin.h:240
static atomic_val_t atomic_and(atomic_t *target, atomic_val_t value)
Atomic bitwise AND.
Definition: atomic_builtin.h:274
static atomic_val_t atomic_get(const atomic_t *target)
Atomic get.
Definition: atomic_builtin.h:138
static atomic_val_t atomic_add(atomic_t *target, atomic_val_t value)
Atomic addition.
Definition: atomic_builtin.h:77
int target
Definition: main.c:68