1 #include <BeOSBuildCompatibility.h> 2 3 #include <string.h> 4 5 #include <OS.h> 6 #include <SupportDefs.h> 7 8 9 #if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 7)) \ 10 && !defined(__clang__) 11 12 13 void 14 atomic_set(int32 *value, int32 newValue) 15 { 16 *value = newValue; 17 } 18 19 20 int32 21 atomic_get_and_set(int32 *value, int32 newValue) 22 { 23 int32 oldValue = *value; 24 *value = newValue; 25 return oldValue; 26 } 27 28 29 int32 30 atomic_test_and_set(int32 *value, int32 newValue, int32 testAgainst) 31 { 32 int32 oldValue = *value; 33 if (oldValue == testAgainst) 34 *value = newValue; 35 return oldValue; 36 } 37 38 39 int32 40 atomic_add(int32 *value, int32 addValue) 41 { 42 int32 oldValue = *value; 43 *value += addValue; 44 return oldValue; 45 } 46 47 48 int32 49 atomic_and(int32 *value, int32 andValue) 50 { 51 int32 oldValue = *value; 52 *value &= andValue; 53 return oldValue; 54 } 55 56 57 int32 58 atomic_or(int32 *value, int32 orValue) 59 { 60 int32 oldValue = *value; 61 *value |= orValue; 62 return oldValue; 63 } 64 65 66 int32 67 atomic_get(int32 *value) 68 { 69 return *value; 70 } 71 72 73 void 74 atomic_set64(int64 *value, int64 newValue) 75 { 76 *value = newValue; 77 } 78 79 80 int64 81 atomic_get_and_set64(int64 *value, int64 newValue) 82 { 83 int64 oldValue = *value; 84 *value = newValue; 85 return oldValue; 86 } 87 88 int64 89 atomic_test_and_set64(int64 *value, int64 newValue, int64 testAgainst) 90 { 91 int64 oldValue = *value; 92 if (oldValue == testAgainst) 93 *value = newValue; 94 return oldValue; 95 } 96 97 int64 98 atomic_add64(int64 *value, int64 addValue) 99 { 100 int64 oldValue = *value; 101 *value += addValue; 102 return oldValue; 103 } 104 105 int64 106 atomic_and64(int64 *value, int64 andValue) 107 { 108 int64 oldValue = *value; 109 *value &= andValue; 110 return oldValue; 111 } 112 113 int64 114 atomic_or64(int64 *value, int64 orValue) 115 { 116 int64 oldValue = *value; 117 *value |= orValue; 118 return oldValue; 119 } 120 121 int64 122 atomic_get64(int64 *value) 123 { 124 return *value; 125 } 126 127 128 #endif // __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 7) 129 130