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