xref: /haiku/src/system/libroot/os/atomic.c (revision 16c83730262f1e4f0fc69d80744bb36dcfbbe3af)
1 /*
2 ** Copyright 2003, Marcus Overhagen. All rights reserved.
3 ** Distributed under the terms of the Haiku License.
4 */
5 
6 
7 #include <SupportDefs.h>
8 
9 #include <syscalls.h>
10 
11 
12 #ifdef ATOMIC_FUNCS_ARE_SYSCALLS
13 
14 int32
15 atomic_set(vint32 *value, int32 newValue)
16 {
17 	return _kern_atomic_set(value, newValue);
18 }
19 
20 int32
21 atomic_test_and_set(vint32 *value, int32 newValue, int32 testAgainst)
22 {
23 	return _kern_atomic_test_and_set(value, newValue, testAgainst);
24 }
25 
26 int32
27 atomic_add(vint32 *value, int32 addValue)
28 {
29 	return _kern_atomic_add(value, addValue);
30 }
31 
32 int32
33 atomic_and(vint32 *value, int32 andValue)
34 {
35 	return _kern_atomic_and(value, andValue);
36 }
37 
38 int32
39 atomic_or(vint32 *value, int32 orValue)
40 {
41 	return _kern_atomic_or(value, orValue);
42 }
43 
44 int32
45 atomic_get(vint32 *value)
46 {
47 	return _kern_atomic_get(value);
48 }
49 
50 #endif	/* ATOMIC_FUNCS_ARE_SYSCALLS */
51 
52 #ifdef ATOMIC64_FUNCS_ARE_SYSCALLS
53 
54 int64
55 atomic_set64(vint64 *value, int64 newValue)
56 {
57 	return _kern_atomic_set64(value, newValue);
58 }
59 
60 int64
61 atomic_test_and_set64(vint64 *value, int64 newValue, int64 testAgainst)
62 {
63 	return _kern_atomic_test_and_set64(value, newValue, testAgainst);
64 }
65 
66 int64
67 atomic_add64(vint64 *value, int64 addValue)
68 {
69 	return _kern_atomic_add64(value, addValue);
70 }
71 
72 int64
73 atomic_and64(vint64 *value, int64 andValue)
74 {
75 	return _kern_atomic_and64(value, andValue);
76 }
77 
78 int64
79 atomic_or64(vint64 *value, int64 orValue)
80 {
81 	return _kern_atomic_or64(value, orValue);
82 }
83 
84 int64
85 atomic_get64(vint64 *value)
86 {
87 	return _kern_atomic_get64(value);
88 }
89 
90 #endif	/* ATOMIC64_FUNCS_ARE_SYSCALLS */
91 
92 #ifdef __ARM__
93 
94 /* GCC compatibility: libstdc++ needs this one.
95  * TODO: Update libstdc++ and drop this.
96  * cf. http://fedoraproject.org/wiki/Architectures/ARM/GCCBuiltInAtomicOperations
97  */
98 extern int32_t __sync_fetch_and_add_4(int32_t *value, int32_t addValue);
99 
100 extern int32_t __sync_fetch_and_add_4(int32_t *value, int32_t addValue)
101 {
102 	return atomic_add((vint32 *)value, addValue);
103 }
104 
105 #endif
106