btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / system / kernel / arch / arm / arch_atomic32.cpp
blob12038f7506be7ec59c44484deb106da2ccfb66d5
1 /*
2 * Copyright 2013 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Ithamar R. Adema, ithamar@upgrade-android.com
7 */
9 #include <KernelExport.h>
11 #include <kernel.h>
12 #include <user_atomic.h>
14 #include <util/AutoLock.h>
16 #ifdef ATOMIC_FUNCS_ARE_SYSCALLS
19 * NOTE: These functions are _intentionally_ not using spinlocks, unlike
20 * the 64 bit versions. The reason for this is that they are used by the
21 * spinlock code itself, and therefore would deadlock.
23 * Since these are only really needed for ARMv5, which is not SMP anyway,
24 * this is an acceptable compromise.
27 void
28 atomic_set(int32 *value, int32 newValue)
30 InterruptsLocker locker;
31 *value = newValue;
34 int32
35 atomic_get_and_set(int32 *value, int32 newValue)
37 InterruptsLocker locker;
38 int32 oldValue = *value;
39 atomic_set(value, newValue);
40 return oldValue;
43 int32
44 atomic_test_and_set(int32 *value, int32 newValue, int32 testAgainst)
46 InterruptsLocker locker;
48 int32 oldValue = *value;
49 if (oldValue == testAgainst)
50 *value = newValue;
51 return oldValue;
54 int32
55 atomic_add(int32 *value, int32 addValue)
57 InterruptsLocker locker;
59 int32 oldValue = *value;
60 *value += addValue;
61 return oldValue;
64 int32
65 atomic_and(int32 *value, int32 andValue)
67 InterruptsLocker locker;
69 int32 oldValue = *value;
70 *value &= andValue;
71 return oldValue;
74 int32
75 atomic_or(int32 *value, int32 orValue)
77 InterruptsLocker locker;
79 int32 oldValue = *value;
80 *value |= orValue;
81 return oldValue;
84 int32
85 atomic_get(int32 *value)
87 InterruptsLocker locker;
89 int32 oldValue = *value;
90 return oldValue;
93 void
94 _user_atomic_set(int32 *value, int32 newValue)
96 if (IS_USER_ADDRESS(value)
97 && lock_memory((void *)value, sizeof(int32), B_READ_DEVICE) == B_OK) {
98 atomic_set(value, newValue);
99 unlock_memory((void *)value, sizeof(int32), B_READ_DEVICE);
100 return;
103 access_violation:
104 // XXX kill application
105 return;
108 int32
109 _user_atomic_get_and_set(int32 *value, int32 newValue)
111 if (IS_USER_ADDRESS(value)
112 && lock_memory((void *)value, sizeof(int32), B_READ_DEVICE) == B_OK) {
113 int32 oldValue = atomic_get_and_set(value, newValue);
114 unlock_memory((void *)value, sizeof(int32), B_READ_DEVICE);
115 return oldValue;
118 access_violation:
119 // XXX kill application
120 return -1;
123 int32
124 _user_atomic_test_and_set(int32 *value, int32 newValue, int32 testAgainst)
126 if (IS_USER_ADDRESS(value)
127 && lock_memory((void *)value, sizeof(int32), B_READ_DEVICE) == B_OK) {
128 int32 oldValue = atomic_test_and_set((int32*)value, newValue, testAgainst);
129 unlock_memory((void *)value, sizeof(int32), B_READ_DEVICE);
130 return oldValue;
133 access_violation:
134 // XXX kill application
135 return -1;
138 int32
139 _user_atomic_add(int32 *value, int32 addValue)
141 if (IS_USER_ADDRESS(value)
142 && lock_memory((void *)value, sizeof(int32), B_READ_DEVICE) == B_OK) {
143 int32 oldValue = atomic_add(value, addValue);
144 unlock_memory((void *)value, sizeof(int32), B_READ_DEVICE);
145 return oldValue;
148 access_violation:
149 // XXX kill application
150 return -1;
153 int32
154 _user_atomic_and(int32 *value, int32 andValue)
156 if (IS_USER_ADDRESS(value)
157 && lock_memory((void *)value, sizeof(int32), B_READ_DEVICE) == B_OK) {
158 int32 oldValue = atomic_and(value, andValue);
159 unlock_memory((void *)value, sizeof(int32), B_READ_DEVICE);
160 return oldValue;
163 access_violation:
164 // XXX kill application
165 return -1;
168 int32
169 _user_atomic_or(int32 *value, int32 orValue)
171 if (IS_USER_ADDRESS(value)
172 && lock_memory((void *)value, sizeof(int32), B_READ_DEVICE) == B_OK) {
173 int32 oldValue = atomic_or(value, orValue);
174 unlock_memory((void *)value, sizeof(int32), B_READ_DEVICE);
175 return oldValue;
178 access_violation:
179 // XXX kill application
180 return -1;
183 int32
184 _user_atomic_get(int32 *value)
186 if (IS_USER_ADDRESS(value)
187 && lock_memory((void *)value, sizeof(int32), B_READ_DEVICE) == B_OK) {
188 int32 oldValue = atomic_get(value);
189 unlock_memory((void *)value, sizeof(int32), B_READ_DEVICE);
190 return oldValue;
193 access_violation:
194 // XXX kill application
195 return -1;
198 #endif /* ATOMIC_FUNCS_ARE_SYSCALLS */