23
23
#ifndef __cplusplus
24
24
#include < stdatomic.h>
25
25
#define z_atomic (X ) _Atomic X
26
+ #define _z_atomic_store_explicit atomic_store_explicit
27
+ #define _z_atomic_fetch_add_explicit atomic_fetch_add_explicit
28
+ #define _z_atomic_fetch_sub_explicit atomic_fetch_sub_explicit
29
+ #define _z_memory_order_acquire memory_order_acquire
30
+ #define _z_memory_order_release memory_order_release
31
+ #define _z_memory_order_relaxed memory_order_relaxed
26
32
#else
27
33
#include < atomic>
28
34
#define z_atomic (X ) std::atomic<X>
29
- using namespace std ;
35
+ #define _z_atomic_store_explicit std::atomic_store_explicit
36
+ #define _z_atomic_fetch_add_explicit std::atomic_fetch_add_explicit
37
+ #define _z_atomic_fetch_sub_explicit std::atomic_fetch_sub_explicit
38
+ #define _z_memory_order_acquire std::memory_order_acquire
39
+ #define _z_memory_order_release std::memory_order_release
40
+ #define _z_memory_order_relaxed std::memory_order_relaxed
30
41
#endif
31
42
32
43
/* ------------------ Internal Array Macros ------------------*/
@@ -42,7 +53,7 @@ using namespace std;
42
53
p._cnt = (z_atomic (unsigned int ) *)z_malloc (sizeof (z_atomic (unsigned int ) *)); \
43
54
if (p._cnt != NULL ) { \
44
55
*p.ptr = val; \
45
- atomic_store_explicit (p._cnt , 1 , memory_order_relaxed); \
56
+ _z_atomic_store_explicit (p._cnt , 1 , _z_memory_order_relaxed); \
46
57
} else { \
47
58
z_free (p.ptr ); \
48
59
} \
@@ -53,15 +64,15 @@ using namespace std;
53
64
name##_sptr_t c; \
54
65
c._cnt = p->_cnt ; \
55
66
c.ptr = p->ptr ; \
56
- atomic_fetch_add_explicit (p->_cnt , 1 , memory_order_relaxed); \
67
+ _z_atomic_fetch_add_explicit (p->_cnt , 1 , _z_memory_order_relaxed); \
57
68
return c; \
58
69
} \
59
70
static inline name##_sptr_t *name##_sptr_clone_as_ptr(name##_sptr_t *p) { \
60
71
name##_sptr_t *c = (name##_sptr_t *)z_malloc (sizeof (name##_sptr_t )); \
61
72
if (c != NULL ) { \
62
73
c->_cnt = p->_cnt ; \
63
74
c->ptr = p->ptr ; \
64
- atomic_fetch_add_explicit (p->_cnt , 1 , memory_order_relaxed); \
75
+ _z_atomic_fetch_add_explicit (p->_cnt , 1 , _z_memory_order_relaxed); \
65
76
} \
66
77
return c; \
67
78
} \
@@ -71,10 +82,10 @@ using namespace std;
71
82
static inline _Bool name##_sptr_drop(name##_sptr_t *p) { \
72
83
_Bool dropped = false ; \
73
84
if (p->_cnt != NULL ) { \
74
- unsigned int c = atomic_fetch_sub_explicit (p->_cnt , 1 , memory_order_release); \
85
+ unsigned int c = _z_atomic_fetch_sub_explicit (p->_cnt , 1 , _z_memory_order_release); \
75
86
dropped = c == 1 ; \
76
87
if (dropped == true ) { \
77
- atomic_thread_fence (memory_order_acquire); \
88
+ atomic_thread_fence (_z_memory_order_acquire); \
78
89
if (p->ptr != NULL ) { \
79
90
type##_clear (p->ptr ); \
80
91
z_free (p->ptr ); \
0 commit comments