comparison include/SDL_atomic.h @ 3216:48a80f2a7ff2

volitile... duh, yeah the variable need to be labeled volitile
author Bob Pendleton <bob@pendleton.com>
date Thu, 09 Jul 2009 21:31:27 +0000
parents 3aa519a5c676
children 916f396fe65d
comparison
equal deleted inserted replaced
3215:b425c3e2b796 3216:48a80f2a7ff2
52 52
53 /* Function prototypes */ 53 /* Function prototypes */
54 54
55 /* 8 bit atomic operations */ 55 /* 8 bit atomic operations */
56 56
57 extern DECLSPEC Uint8 SDLCALL SDL_AtomicExchange8(Uint8 * ptr, Uint8 value); 57 extern DECLSPEC Uint8 SDLCALL SDL_AtomicExchange8(volatile Uint8 * ptr, Uint8 value);
58 extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCompareThenSet8(Uint8 * ptr, 58 extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCompareThenSet8(volatile Uint8 * ptr,
59 Uint8 oldvalue, Uint8 newvalue); 59 Uint8 oldvalue, Uint8 newvalue);
60 extern DECLSPEC SDL_bool SDLCALL SDL_AtomicTestThenSet8(Uint8 * ptr); 60 extern DECLSPEC SDL_bool SDLCALL SDL_AtomicTestThenSet8(volatile Uint8 * ptr);
61 extern DECLSPEC void SDLCALL SDL_AtomicClear8(Uint8 * ptr); 61 extern DECLSPEC void SDLCALL SDL_AtomicClear8(volatile Uint8 * ptr);
62 extern DECLSPEC Uint8 SDLCALL SDL_AtomicFetchThenIncrement8(Uint8 * ptr); 62 extern DECLSPEC Uint8 SDLCALL SDL_AtomicFetchThenIncrement8(volatile Uint8 * ptr);
63 extern DECLSPEC Uint8 SDLCALL SDL_AtomicFetchThenDecrement8(Uint8 * ptr); 63 extern DECLSPEC Uint8 SDLCALL SDL_AtomicFetchThenDecrement8(volatile Uint8 * ptr);
64 extern DECLSPEC Uint8 SDLCALL SDL_AtomicFetchThenAdd8(Uint8 * ptr, Uint8 value); 64 extern DECLSPEC Uint8 SDLCALL SDL_AtomicFetchThenAdd8(volatile Uint8 * ptr, Uint8 value);
65 extern DECLSPEC Uint8 SDLCALL SDL_AtomicFetchThenSubtract8(Uint8 * ptr, Uint8 value); 65 extern DECLSPEC Uint8 SDLCALL SDL_AtomicFetchThenSubtract8(volatile Uint8 * ptr, Uint8 value);
66 extern DECLSPEC Uint8 SDLCALL SDL_AtomicIncrementThenFetch8(Uint8 * ptr); 66 extern DECLSPEC Uint8 SDLCALL SDL_AtomicIncrementThenFetch8(volatile Uint8 * ptr);
67 extern DECLSPEC Uint8 SDLCALL SDL_AtomicDecrementThenFetch8(Uint8 * ptr); 67 extern DECLSPEC Uint8 SDLCALL SDL_AtomicDecrementThenFetch8(volatile Uint8 * ptr);
68 extern DECLSPEC Uint8 SDLCALL SDL_AtomicAddThenFetch8(Uint8 * ptr, Uint8 value); 68 extern DECLSPEC Uint8 SDLCALL SDL_AtomicAddThenFetch8(volatile Uint8 * ptr, Uint8 value);
69 extern DECLSPEC Uint8 SDLCALL SDL_AtomicSubtractThenFetch8(Uint8 * ptr, Uint8 value); 69 extern DECLSPEC Uint8 SDLCALL SDL_AtomicSubtractThenFetch8(volatile Uint8 * ptr, Uint8 value);
70 70
71 /* 16 bit atomic operations */ 71 /* 16 bit atomic operations */
72 72
73 extern DECLSPEC Uint16 SDLCALL SDL_AtomicExchange16(Uint16 * ptr, Uint16 value); 73 extern DECLSPEC Uint16 SDLCALL SDL_AtomicExchange16(volatile Uint16 * ptr, Uint16 value);
74 extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCompareThenSet16(Uint16 * ptr, 74 extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCompareThenSet16(volatile Uint16 * ptr,
75 Uint16 oldvalue, Uint16 newvalue); 75 Uint16 oldvalue, Uint16 newvalue);
76 extern DECLSPEC SDL_bool SDLCALL SDL_AtomicTestThenSet16(Uint16 * ptr); 76 extern DECLSPEC SDL_bool SDLCALL SDL_AtomicTestThenSet16(volatile Uint16 * ptr);
77 extern DECLSPEC void SDLCALL SDL_AtomicClear16(Uint16 * ptr); 77 extern DECLSPEC void SDLCALL SDL_AtomicClear16(volatile Uint16 * ptr);
78 extern DECLSPEC Uint16 SDLCALL SDL_AtomicFetchThenIncrement16(Uint16 * ptr); 78 extern DECLSPEC Uint16 SDLCALL SDL_AtomicFetchThenIncrement16(volatile Uint16 * ptr);
79 extern DECLSPEC Uint16 SDLCALL SDL_AtomicFetchThenDecrement16(Uint16 * ptr); 79 extern DECLSPEC Uint16 SDLCALL SDL_AtomicFetchThenDecrement16(volatile Uint16 * ptr);
80 extern DECLSPEC Uint16 SDLCALL SDL_AtomicFetchThenAdd16(Uint16 * ptr, Uint16 value); 80 extern DECLSPEC Uint16 SDLCALL SDL_AtomicFetchThenAdd16(volatile Uint16 * ptr, Uint16 value);
81 extern DECLSPEC Uint16 SDLCALL SDL_AtomicFetchThenSubtract16(Uint16 * ptr, Uint16 value); 81 extern DECLSPEC Uint16 SDLCALL SDL_AtomicFetchThenSubtract16(volatile Uint16 * ptr, Uint16 value);
82 extern DECLSPEC Uint16 SDLCALL SDL_AtomicIncrementThenFetch16(Uint16 * ptr); 82 extern DECLSPEC Uint16 SDLCALL SDL_AtomicIncrementThenFetch16(volatile Uint16 * ptr);
83 extern DECLSPEC Uint16 SDLCALL SDL_AtomicDecrementThenFetch16(Uint16 * ptr); 83 extern DECLSPEC Uint16 SDLCALL SDL_AtomicDecrementThenFetch16(volatile Uint16 * ptr);
84 extern DECLSPEC Uint16 SDLCALL SDL_AtomicAddThenFetch16(Uint16 * ptr, Uint16 value); 84 extern DECLSPEC Uint16 SDLCALL SDL_AtomicAddThenFetch16(volatile Uint16 * ptr, Uint16 value);
85 extern DECLSPEC Uint16 SDLCALL SDL_AtomicSubtractThenFetch16(Uint16 * ptr, Uint16 value); 85 extern DECLSPEC Uint16 SDLCALL SDL_AtomicSubtractThenFetch16(volatile Uint16 * ptr, Uint16 value);
86 86
87 /* 32 bit atomic operations */ 87 /* 32 bit atomic operations */
88 88
89 /** 89 /**
90 * \fn int SDL_AtomicExchange32(Uint32 * ptr, Uint32 value) 90 * \fn int SDL_AtomicExchange32(volatile Uint32 * ptr, Uint32 value)
91 * 91 *
92 * \brief Atomically exchange two 32 bit values. 92 * \brief Atomically exchange two 32 bit values.
93 * 93 *
94 * \return the value point to by ptr. 94 * \return the value point to by ptr.
95 * 95 *
98 * 98 *
99 * The current value stored at *ptr is returned and it is replaced 99 * The current value stored at *ptr is returned and it is replaced
100 * with value. This function can be used to implement SDL_TestThenSet. 100 * with value. This function can be used to implement SDL_TestThenSet.
101 * 101 *
102 */ 102 */
103 extern DECLSPEC Uint32 SDLCALL SDL_AtomicExchange32(Uint32 * ptr, Uint32 value); 103 extern DECLSPEC Uint32 SDLCALL SDL_AtomicExchange32(volatile Uint32 * ptr, Uint32 value);
104 /** 104 /**
105 * \fn int SDL_AtomicCompareThenSet32(Uint32 * ptr, Uint32 oldvalue, Uint32 newvalue) 105 * \fn int SDL_AtomicCompareThenSet32(volatile Uint32 * ptr, Uint32 oldvalue, Uint32 newvalue)
106 * 106 *
107 * \brief If *ptr == oldvalue then replace the contents of *ptr by new value. 107 * \brief If *ptr == oldvalue then replace the contents of *ptr by new value.
108 * 108 *
109 * \return true if the newvalue was stored. 109 * \return true if the newvalue was stored.
110 * 110 *
111 * \param *ptr is the value to be compared and replaced. 111 * \param *ptr is the value to be compared and replaced.
112 * \param oldvalue is value to be compared to *ptr. 112 * \param oldvalue is value to be compared to *ptr.
113 * \param newvalue is value to be stored at *ptr. 113 * \param newvalue is value to be stored at *ptr.
114 * 114 *
115 */ 115 */
116 extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCompareThenSet32(Uint32 * ptr, 116 extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCompareThenSet32(volatile Uint32 * ptr,
117 Uint32 oldvalue, Uint32 newvalue); 117 Uint32 oldvalue, Uint32 newvalue);
118 /** 118 /**
119 * \fn SDL_bool SDL_AtomicTestThenSet32(Uint32 * ptr); 119 * \fn SDL_bool SDL_AtomicTestThenSet32(volatile Uint32 * ptr);
120 * 120 *
121 * \brief Check to see if *ptr == 0 and set it to non-zero. 121 * \brief Check to see if *ptr == 0 and set it to non-zero.
122 * 122 *
123 * \return SDL_True if the value pointed to by ptr was zero and 123 * \return SDL_True if the value pointed to by ptr was zero and
124 * SDL_False if it was not zero 124 * SDL_False if it was not zero
125 * 125 *
126 * \param ptr points to the value to be tested and set. 126 * \param ptr points to the value to be tested and set.
127 * 127 *
128 */ 128 */
129 extern DECLSPEC SDL_bool SDLCALL SDL_AtomicTestThenSet32(Uint32 * ptr); 129 extern DECLSPEC SDL_bool SDLCALL SDL_AtomicTestThenSet32(volatile Uint32 * ptr);
130 /** 130 /**
131 * \fn void SDL_AtomicClear32(Uint32 * ptr); 131 * \fn void SDL_AtomicClear32(volatile Uint32 * ptr);
132 * 132 *
133 * \brief set the value pointed to by ptr to be zero. 133 * \brief set the value pointed to by ptr to be zero.
134 * 134 *
135 * \param ptr address of the value to be set to zero 135 * \param ptr address of the value to be set to zero
136 * 136 *
137 */ 137 */
138 extern DECLSPEC void SDLCALL SDL_AtomicClear32(Uint32 * ptr); 138 extern DECLSPEC void SDLCALL SDL_AtomicClear32(volatile Uint32 * ptr);
139 /** 139 /**
140 * \fn Uint32 SDL_AtomicFetchThenIncrement32(Uint32 * ptr); 140 * \fn Uint32 SDL_AtomicFetchThenIncrement32(volatile Uint32 * ptr);
141 * 141 *
142 * \brief fetch the current value of *ptr and then increment that 142 * \brief fetch the current value of *ptr and then increment that
143 * value in place. 143 * value in place.
144 * 144 *
145 * \return the value before it was incremented. 145 * \return the value before it was incremented.
146 * 146 *
147 * \param ptr address of the value to fetch and increment 147 * \param ptr address of the value to fetch and increment
148 * 148 *
149 */ 149 */
150 extern DECLSPEC Uint32 SDLCALL SDL_AtomicFetchThenIncrement32(Uint32 * ptr); 150 extern DECLSPEC Uint32 SDLCALL SDL_AtomicFetchThenIncrement32(volatile Uint32 * ptr);
151 /** 151 /**
152 * \fn Uint32 SDL_AtomicFetchThenDecrement32(Uint32 * ptr); 152 * \fn Uint32 SDL_AtomicFetchThenDecrement32(volatile Uint32 * ptr);
153 * 153 *
154 * \brief fetch *ptr and then decrement the value in place. 154 * \brief fetch *ptr and then decrement the value in place.
155 * 155 *
156 * \return the value before it was decremented. 156 * \return the value before it was decremented.
157 * 157 *
158 * \param ptr address of the value to fetch and drement 158 * \param ptr address of the value to fetch and drement
159 * 159 *
160 */ 160 */
161 extern DECLSPEC Uint32 SDLCALL SDL_AtomicFetchThenDecrement32(Uint32 * ptr); 161 extern DECLSPEC Uint32 SDLCALL SDL_AtomicFetchThenDecrement32(volatile Uint32 * ptr);
162 /** 162 /**
163 * \fn Uint32 SDL_AtomicFetchThenAdd32(Uint32 * ptr, Uint32 value); 163 * \fn Uint32 SDL_AtomicFetchThenAdd32(volatile Uint32 * ptr, Uint32 value);
164 * 164 *
165 * \brief fetch the current value at ptr and then add value to *ptr. 165 * \brief fetch the current value at ptr and then add value to *ptr.
166 * 166 *
167 * \return *ptr before the addition took place. 167 * \return *ptr before the addition took place.
168 * 168 *
169 * \param ptr the address of data we are changing. 169 * \param ptr the address of data we are changing.
170 * \param value the value to add to *ptr. 170 * \param value the value to add to *ptr.
171 * 171 *
172 */ 172 */
173 extern DECLSPEC Uint32 SDLCALL SDL_AtomicFetchThenAdd32(Uint32 * ptr, Uint32 value); 173 extern DECLSPEC Uint32 SDLCALL SDL_AtomicFetchThenAdd32(volatile Uint32 * ptr, Uint32 value);
174 /** 174 /**
175 * \fn Uint32 SDL_AtomicFetchThenSubtract32(Uint32 * ptr, Uint32 value); 175 * \fn Uint32 SDL_AtomicFetchThenSubtract32(volatile Uint32 * ptr, Uint32 value);
176 * 176 *
177 * \brief Fetch *ptr and then subtract value from it. 177 * \brief Fetch *ptr and then subtract value from it.
178 * 178 *
179 * \return *ptr before the subtraction took place. 179 * \return *ptr before the subtraction took place.
180 * 180 *
181 * \param ptr the address of the data being changed. 181 * \param ptr the address of the data being changed.
182 * \param value the value to subtract from *ptr. 182 * \param value the value to subtract from *ptr.
183 * 183 *
184 */ 184 */
185 extern DECLSPEC Uint32 SDLCALL SDL_AtomicFetchThenSubtract32(Uint32 * ptr, Uint32 value); 185 extern DECLSPEC Uint32 SDLCALL SDL_AtomicFetchThenSubtract32(volatile Uint32 * ptr, Uint32 value);
186 /** 186 /**
187 * \fn Uint32 SDL_AtomicIncrementThenFetch32(Uint32 * ptr); 187 * \fn Uint32 SDL_AtomicIncrementThenFetch32(volatile Uint32 * ptr);
188 * 188 *
189 * \brief Add one to the data pointed to by ptr and return that value. 189 * \brief Add one to the data pointed to by ptr and return that value.
190 * 190 *
191 * \return the incremented value. 191 * \return the incremented value.
192 * 192 *
193 * \param ptr address of the data to increment. 193 * \param ptr address of the data to increment.
194 * 194 *
195 */ 195 */
196 extern DECLSPEC Uint32 SDLCALL SDL_AtomicIncrementThenFetch32(Uint32 * ptr); 196 extern DECLSPEC Uint32 SDLCALL SDL_AtomicIncrementThenFetch32(volatile Uint32 * ptr);
197 /** 197 /**
198 * \fn Uint32 SDL_AtomicDecrementThenFetch32(Uint32 * ptr); 198 * \fn Uint32 SDL_AtomicDecrementThenFetch32(volatile Uint32 * ptr);
199 * 199 *
200 * \brief Subtract one from data pointed to by ptr and return the new value. 200 * \brief Subtract one from data pointed to by ptr and return the new value.
201 * 201 *
202 * \return The decremented value. 202 * \return The decremented value.
203 * 203 *
204 * \param ptr The address of the data to decrement. 204 * \param ptr The address of the data to decrement.
205 * 205 *
206 */ 206 */
207 extern DECLSPEC Uint32 SDLCALL SDL_AtomicDecrementThenFetch32(Uint32 * ptr); 207 extern DECLSPEC Uint32 SDLCALL SDL_AtomicDecrementThenFetch32(volatile Uint32 * ptr);
208 /** 208 /**
209 * \fn Uint32 SDL_AtomicAddThenFetch32(Uint32 * ptr, Uint32 value); 209 * \fn Uint32 SDL_AtomicAddThenFetch32(volatile Uint32 * ptr, Uint32 value);
210 * 210 *
211 * \brief Add value to the data pointed to by ptr and return result. 211 * \brief Add value to the data pointed to by ptr and return result.
212 * 212 *
213 * \return The sum of *ptr and value. 213 * \return The sum of *ptr and value.
214 * 214 *
215 * \param ptr The address of the data to be modified. 215 * \param ptr The address of the data to be modified.
216 * \param value The value to be added. 216 * \param value The value to be added.
217 * 217 *
218 */ 218 */
219 extern DECLSPEC Uint32 SDLCALL SDL_AtomicAddThenFetch32(Uint32 * ptr, Uint32 value); 219 extern DECLSPEC Uint32 SDLCALL SDL_AtomicAddThenFetch32(volatile Uint32 * ptr, Uint32 value);
220 /** 220 /**
221 * \fn Uint32 SDL_AtomicSubtractThenFetch32(Uint32 * ptr, Uint32 value); 221 * \fn Uint32 SDL_AtomicSubtractThenFetch32(volatile Uint32 * ptr, Uint32 value);
222 * 222 *
223 * \brief Subtract value from the data pointed to by ptr and return the result. 223 * \brief Subtract value from the data pointed to by ptr and return the result.
224 * 224 *
225 * \return the difference between *ptr and value. 225 * \return the difference between *ptr and value.
226 * 226 *
227 * \param ptr The address of the data to be modified. 227 * \param ptr The address of the data to be modified.
228 * \param value The value to be subtracted. 228 * \param value The value to be subtracted.
229 * 229 *
230 */ 230 */
231 extern DECLSPEC Uint32 SDLCALL SDL_AtomicSubtractThenFetch32(Uint32 * ptr, Uint32 value); 231 extern DECLSPEC Uint32 SDLCALL SDL_AtomicSubtractThenFetch32(volatile Uint32 * ptr, Uint32 value);
232 232
233 /* 64 bit atomic operations */ 233 /* 64 bit atomic operations */
234 #ifdef SDL_HAS_64BIT_TYPE 234 #ifdef SDL_HAS_64BIT_TYPE
235 235
236 extern DECLSPEC Uint64 SDLCALL SDL_AtomicExchange64(Uint64 * ptr, Uint64 value); 236 extern DECLSPEC Uint64 SDLCALL SDL_AtomicExchange64(volatile Uint64 * ptr, Uint64 value);
237 extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCompareThenSet64(Uint64 * ptr, 237 extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCompareThenSet64(volatile Uint64 * ptr,
238 Uint64 oldvalue, Uint64 newvalue); 238 Uint64 oldvalue, Uint64 newvalue);
239 extern DECLSPEC SDL_bool SDLCALL SDL_AtomicTestThenSet64(Uint64 * ptr); 239 extern DECLSPEC SDL_bool SDLCALL SDL_AtomicTestThenSet64(volatile Uint64 * ptr);
240 extern DECLSPEC void SDLCALL SDL_AtomicClear64(Uint64 * ptr); 240 extern DECLSPEC void SDLCALL SDL_AtomicClear64(volatile Uint64 * ptr);
241 extern DECLSPEC Uint64 SDLCALL SDL_AtomicFetchThenIncrement64(Uint64 * ptr); 241 extern DECLSPEC Uint64 SDLCALL SDL_AtomicFetchThenIncrement64(volatile Uint64 * ptr);
242 extern DECLSPEC Uint64 SDLCALL SDL_AtomicFetchThenDecrement64(Uint64 * ptr); 242 extern DECLSPEC Uint64 SDLCALL SDL_AtomicFetchThenDecrement64(volatile Uint64 * ptr);
243 extern DECLSPEC Uint64 SDLCALL SDL_AtomicFetchThenAdd64(Uint64 * ptr, Uint64 value); 243 extern DECLSPEC Uint64 SDLCALL SDL_AtomicFetchThenAdd64(volatile Uint64 * ptr, Uint64 value);
244 extern DECLSPEC Uint64 SDLCALL SDL_AtomicFetchThenSubtract64(Uint64 * ptr, Uint64 value); 244 extern DECLSPEC Uint64 SDLCALL SDL_AtomicFetchThenSubtract64(volatile Uint64 * ptr, Uint64 value);
245 extern DECLSPEC Uint64 SDLCALL SDL_AtomicIncrementThenFetch64(Uint64 * ptr); 245 extern DECLSPEC Uint64 SDLCALL SDL_AtomicIncrementThenFetch64(volatile Uint64 * ptr);
246 extern DECLSPEC Uint64 SDLCALL SDL_AtomicDecrementThenFetch64(Uint64 * ptr); 246 extern DECLSPEC Uint64 SDLCALL SDL_AtomicDecrementThenFetch64(volatile Uint64 * ptr);
247 extern DECLSPEC Uint64 SDLCALL SDL_AtomicAddThenFetch64(Uint64 * ptr, Uint64 value); 247 extern DECLSPEC Uint64 SDLCALL SDL_AtomicAddThenFetch64(volatile Uint64 * ptr, Uint64 value);
248 extern DECLSPEC Uint64 SDLCALL SDL_AtomicSubtractThenFetch64(Uint64 * ptr, Uint64 value); 248 extern DECLSPEC Uint64 SDLCALL SDL_AtomicSubtractThenFetch64(volatile Uint64 * ptr, Uint64 value);
249 #endif /* SDL_HAS_64BIT_TYPE */ 249 #endif /* SDL_HAS_64BIT_TYPE */
250 250
251 /* Ends C function definitions when using C++ */ 251 /* Ends C function definitions when using C++ */
252 #ifdef __cplusplus 252 #ifdef __cplusplus
253 /* *INDENT-OFF* */ 253 /* *INDENT-OFF* */