Changeset 67a56d37474d1336d5e7e07d07f5b1241c66654c
- Timestamp:
- 03/06/08 16:55:06 (5 years ago)
- git-parent:
- Files:
-
- src/utils/noit_atomic.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
src/utils/noit_atomic.h
r3b3b432 r67a56d3 21 21 #define noit_atomic_cas32(ref,new,old) (OSAtomicCompareAndSwap32(old,new,ref) ? old : new) 22 22 #define noit_atomic_cas64(ref,new,old) (OSAtomicCompareAndSwap64(old,new,ref) ? old : new) 23 #define noit_atomic_add32(ref,diff) OSAtomicAdd32(ref,diff) 24 #define noit_atomic_add64(ref,diff) OSAtomicAdd64(ref,diff) 25 #define noit_atomic_sub32(ref,diff) OSAtomicAdd32(ref,0-(diff)) 26 #define noit_atomic_sub64(ref,diff) OSAtomicAdd64(ref,0-(diff)) 23 27 #define noit_atomic_inc32(ref) OSAtomicIncrement32(ref) 24 28 #define noit_atomic_inc64(ref) OSAtomicIncrement64(ref) … … 92 96 while(noit_atomic_cas32(lock, 0, 1) != 1); 93 97 } 94 static inline noit_spinlock_trylock(volatile noit_spinlock_t *lock) {98 static inline int noit_spinlock_trylock(volatile noit_spinlock_t *lock) { 95 99 return (noit_atomic_cas32(lock, 1, 0) == 0); 96 100 } … … 100 104 #endif 101 105 106 #ifndef noit_atomic_add32 107 static inline void noit_atomic_add32(volatile noit_atomic32_t *loc, 108 volatile noit_atomic32_t diff) { 109 register noit_atomic32_t current; 110 do { 111 current = *(loc); 112 } while(noit_atomic_cas32(loc, current + diff, current) != current); 113 } 102 114 #endif 115 116 #ifndef noit_atomic_add64 117 static inline void noit_atomic_add64(volatile noit_atomic64_t *loc, 118 volatile noit_atomic64_t diff) { 119 register noit_atomic64_t current; 120 do { 121 current = *(loc); 122 } while(noit_atomic_cas64(loc, current + diff, current) != current); 123 } 124 #endif 125 126 #ifndef noit_atomic_sub32 127 static inline void noit_atomic_sub32(volatile noit_atomic32_t *loc, 128 volatile noit_atomic32_t diff) { 129 register noit_atomic32_t current; 130 do { 131 current = *(loc); 132 } while(noit_atomic_cas32(loc, current - diff, current) != current); 133 } 134 #endif 135 136 #ifndef noit_atomic_sub64 137 static inline void noit_atomic_sub64(volatile noit_atomic64_t *loc, 138 volatile noit_atomic64_t diff) { 139 register noit_atomic64_t current; 140 do { 141 current = *(loc); 142 } while(noit_atomic_cas64(loc, current - diff, current) != current); 143 } 144 #endif 145 146 #ifndef noit_atomic_inc32 147 #define noit_atomic_inc32(a) noit_atomic_add32(a, 1) 148 #endif 149 150 #ifndef noit_atomic_inc64 151 #define noit_atomic_inc64(a) noit_atomic_add64(a, 1) 152 #endif 153 154 #ifndef noit_atomic_dec32 155 #define noit_atomic_dec32(a) noit_atomic_add32(a, -1) 156 #endif 157 158 #ifndef noit_atomic_dec64 159 #define noit_atomic_dec64(a) noit_atomic_add64(a, -1) 160 #endif 161 162 #endif
