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