blob: 84bcb43b267a9093f5e53dc0aa1ff73a928d311e (
plain)
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
58
59
60
|
$OpenBSD$
Index: src/util/u_atomic.c
--- src/util/u_atomic.c.orig
+++ src/util/u_atomic.c
@@ -32,6 +32,21 @@
#define WEAK
#endif
+#ifdef __clang__
+#pragma clang diagnostic ignored "-Wmissing-prototypes"
+#pragma redefine_extname __sync_add_and_fetch_8_c __sync_add_and_fetch_8
+#pragma redefine_extname __sync_sub_and_fetch_8_c __sync_sub_and_fetch_8
+#pragma redefine_extname __sync_fetch_and_add_8_c __sync_fetch_and_add_8
+#pragma redefine_extname __sync_fetch_and_sub_8_c __sync_fetch_and_sub_8
+#pragma redefine_extname __sync_val_compare_and_swap_8_c \
+ __sync_val_compare_and_swap_8
+#define __sync_add_and_fetch_8 __sync_add_and_fetch_8_c
+#define __sync_sub_and_fetch_8 __sync_sub_and_fetch_8_c
+#define __sync_fetch_and_add_8 __sync_fetch_and_add_8_c
+#define __sync_fetch_and_sub_8 __sync_fetch_and_sub_8_c
+#define __sync_val_compare_and_swap_8 __sync_val_compare_and_swap_8_c
+#endif
+
static pthread_mutex_t sync_mutex = PTHREAD_MUTEX_INITIALIZER;
WEAK uint64_t
@@ -55,6 +70,32 @@ __sync_sub_and_fetch_8(uint64_t *ptr, uint64_t val)
pthread_mutex_lock(&sync_mutex);
*ptr -= val;
r = *ptr;
+ pthread_mutex_unlock(&sync_mutex);
+
+ return r;
+}
+
+WEAK uint64_t
+__sync_fetch_and_add_8(uint64_t *ptr, uint64_t val)
+{
+ uint64_t r;
+
+ pthread_mutex_lock(&sync_mutex);
+ r = *ptr;
+ *ptr += val;
+ pthread_mutex_unlock(&sync_mutex);
+
+ return r;
+}
+
+WEAK uint64_t
+__sync_fetch_and_sub_8(uint64_t *ptr, uint64_t val)
+{
+ uint64_t r;
+
+ pthread_mutex_lock(&sync_mutex);
+ r = *ptr;
+ *ptr -= val;
pthread_mutex_unlock(&sync_mutex);
return r;
|