This repository was archived by the owner on Jul 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathatomic.hpp
57 lines (46 loc) · 2.17 KB
/
atomic.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright 2022 The Jule Programming Language.
// Use of this source code is governed by a BSD 3-Clause
// license that can be found in the LICENSE file.
#ifndef __JULE_ATOMIC_HPP
#define __JULE_ATOMIC_HPP
#define __jule_atomic_store_explicit(ADDR, VAL, MO) \
__extension__({ \
auto atomic_store_ptr{ ADDR }; \
__typeof__((void)(0), *atomic_store_ptr) atomic_store_tmp{ VAL }; \
__atomic_store(atomic_store_ptr, &atomic_store_tmp, MO); \
})
#define __jule_atomic_store(ADDR, VAL) \
__jule_atomic_store_explicit(ADDR, VAL, __ATOMIC_SEQ_CST)
#define __jule_atomic_load_explicit(ADDR, MO) \
__extension__({ \
auto atomic_load_ptr{ ADDR }; \
__typeof__((void)(0), *atomic_load_ptr) atomic_load_tmp; \
__atomic_load(atomic_load_ptr, &atomic_load_tmp, MO); \
atomic_load_tmp; \
})
#define __jule_atomic_load(ADDR) \
__jule_atomic_load_explicit(ADDR, __ATOMIC_SEQ_CST)
#define __jule_atomic_swap_explicit(ADDR, NEW, MO) \
__extension__({ \
auto atomic_exchange_ptr{ ADDR }; \
__typeof__((void)(0), *atomic_exchange_ptr) atomic_exchange_val{ NEW }; \
__typeof__((void)(0), *atomic_exchange_ptr) atomic_exchange_tmp; \
__atomic_exchange(atomic_exchange_ptr, &atomic_exchange_val, \
&atomic_exchange_tmp, MO); \
atomic_exchange_tmp;\
})
#define __jule_atomic_swap(ADDR, NEW) \
__jule_atomic_swap_explicit(ADDR, NEW, __ATOMIC_SEQ_CST)
#define __jule_atomic_compare_swap_explicit(ADDR, OLD, NEW, SUC, FAIL) \
__extension__({ \
auto atomic_compare_exchange_ptr{ ADDR }; \
__typeof__((void)(0), *atomic_compare_exchange_ptr) atomic_compare_exchange_tmp{ NEW }; \
__atomic_compare_exchange (atomic_compare_exchange_ptr, OLD, \
&atomic_compare_exchange_tmp, 0, SUC, FAIL); \
})
#define __jule_atomic_compare_swap(ADDR, OLD, NEW) \
__jule_atomic_compare_swap_explicit(ADDR, OLD, NEW, \
__ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)
#define __jule_atomic_add(ADDR, DELTA) \
__atomic_fetch_add(ADDR, DELTA, __ATOMIC_SEQ_CST)
#endif // #ifndef __JULE_ATOMIC_HPP