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