ClearCore Library
Loading...
Searching...
No Matches
atomic_utils.h
1/*
2 * Copyright (c) 2020 Teknic, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23/*
24 * atomic_utils.h
25 *
26 * Defines macros to aid in atomic gcc operations
27 */
28
29#ifndef __ATOMIC_UTILS_H_
30#define __ATOMIC_UTILS_H_
31
32#define atomic_store_n(ptr, val) __atomic_store_n(ptr, val, __ATOMIC_RELEASE)
33
34#define atomic_or_fetch(ptr, val) \
35 __atomic_or_fetch(ptr, val, __ATOMIC_ACQ_REL)
36#define atomic_fetch_or(ptr, val) \
37 __atomic_fetch_or(ptr, val, __ATOMIC_ACQ_REL)
38
39#define atomic_xor_fetch(ptr, val) \
40 __atomic_xor_fetch(ptr, val, __ATOMIC_ACQ_REL)
41
42#define atomic_fetch_and(ptr, val) \
43 __atomic_fetch_and(ptr, val, __ATOMIC_ACQ_REL)
44#define atomic_and_fetch(ptr, val) \
45 __atomic_and_fetch(ptr, val, __ATOMIC_ACQ_REL)
46
47#define atomic_fetch_add(ptr, val) \
48 __atomic_fetch_add(ptr, val, __ATOMIC_ACQ_REL)
49#define atomic_add_fetch(ptr, val) \
50 __atomic_add_fetch(ptr, val, __ATOMIC_ACQ_REL)
51
52#define atomic_load(ptr, ret) \
53 __atomic_load(ptr, ret, __ATOMIC_CONSUME)
54
55#define atomic_load_n(ptr) __atomic_load_n(ptr, __ATOMIC_CONSUME)
56#define atomic_load_n_relaxed(ptr) __atomic_load_n(ptr, __ATOMIC_RELAXED)
57
58#define atomic_exchange(ptr, val, ret) \
59 __atomic_exchange(ptr, val, ret, __ATOMIC_ACQ_REL)
60#define atomic_exchange_n(ptr, val) \
61 __atomic_exchange_n(ptr, val, __ATOMIC_ACQ_REL)
62
63#define atomic_test_and_set(ptr) __atomic_test_and_set(ptr, __ATOMIC_ACQUIRE)
64
65#define atomic_clear(ptr) __atomic_clear(ptr, __ATOMIC_RELEASE)
66
67#define atomic_test_and_set_acqrel(ptr) __atomic_test_and_set(ptr, __ATOMIC_ACQ_REL)
68
69#define atomic_clear_seqcst(ptr) __atomic_clear(ptr, __ATOMIC_SEQ_CST)
70
71#endif /* __ATOMICGCC_H_ */