Line 0
Link Here
|
|
|
1 |
--- packages/semweb/memory.h.orig 2020-05-29 15:03:22 UTC |
2 |
+++ packages/semweb/memory.h |
3 |
@@ -85,14 +85,18 @@ MSB(unsigned int i) |
4 |
#define MEMORY_BARRIER() __atomic_thread_fence(__ATOMIC_SEQ_CST) |
5 |
#define PREFETCH_FOR_WRITE(p) __builtin_prefetch(p, 1, 0) |
6 |
#define PREFETCH_FOR_READ(p) __builtin_prefetch(p, 0, 0) |
7 |
-#define ATOMIC_ADD(ptr, v) __atomic_add_fetch(ptr, v, __ATOMIC_SEQ_CST) |
8 |
-#define ATOMIC_SUB(ptr, v) __atomic_sub_fetch(ptr, v, __ATOMIC_SEQ_CST) |
9 |
+#define ATOMIC_ADD(ptr, v) (sizeof(v) > sizeof(void *) \ |
10 |
+ ? __sync_add_and_fetch(ptr, v) \ |
11 |
+ : __atomic_add_fetch(ptr, v, __ATOMIC_SEQ_CST)) |
12 |
+#define ATOMIC_SUB(ptr, v) (sizeof(v) > sizeof(void *) \ |
13 |
+ ? __sync_sub_and_fetch(ptr, v) \ |
14 |
+ : __atomic_sub_fetch(ptr, v, __ATOMIC_SEQ_CST)) |
15 |
#define ATOMIC_INC(ptr) ATOMIC_ADD(ptr, 1) /* ++(*ptr) */ |
16 |
#define ATOMIC_DEC(ptr) ATOMIC_SUB(ptr, 1) /* --(*ptr) */ |
17 |
|
18 |
-#define __COMPARE_AND_SWAP(at, from, to) \ |
19 |
- __atomic_compare_exchange_n(at, &(from), to, FALSE, \ |
20 |
- __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) |
21 |
+#define __COMPARE_AND_SWAP(at, from, to) (sizeof(from) > sizeof(void *) \ |
22 |
+ ? __atomic_compare_exchange(at, &(from), &(to), FALSE, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) \ |
23 |
+ : __atomic_compare_exchange_n(at, &(from), to, FALSE, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) |
24 |
|
25 |
static inline int |
26 |
COMPARE_AND_SWAP_PTR(void *at, void *from, void *to) |