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