@@ -202,175 +202,16 @@ MBED_FORCEINLINE void core_util_atomic_flag_clear(volatile core_util_atomic_flag
202
202
*/
203
203
bool core_util_atomic_cas_u8 (volatile uint8_t * ptr , uint8_t * expectedCurrentValue , uint8_t desiredValue );
204
204
205
- /**
206
- * Atomic compare and set. It compares the contents of a memory location to a
207
- * given value and, only if they are the same, modifies the contents of that
208
- * memory location to a given new value. This is done as a single atomic
209
- * operation. The atomicity guarantees that the new value is calculated based on
210
- * up-to-date information; if the value had been updated by another thread in
211
- * the meantime, the write would fail due to a mismatched expectedCurrentValue.
212
- *
213
- * Refer to https://en.wikipedia.org/wiki/Compare-and-set [which may redirect
214
- * you to the article on compare-and swap].
215
- *
216
- * @param ptr The target memory location.
217
- * @param[in,out] expectedCurrentValue A pointer to some location holding the
218
- * expected current value of the data being set atomically.
219
- * The computed 'desiredValue' should be a function of this current value.
220
- * @note: This is an in-out parameter. In the
221
- * failure case of atomic_cas (where the
222
- * destination isn't set), the pointee of expectedCurrentValue is
223
- * updated with the current value.
224
- * @param[in] desiredValue The new value computed based on '*expectedCurrentValue'.
225
- *
226
- * @return true if the memory location was atomically
227
- * updated with the desired value (after verifying
228
- * that it contained the expectedCurrentValue),
229
- * false otherwise. In the failure case,
230
- * exepctedCurrentValue is updated with the new
231
- * value of the target memory location.
232
- *
233
- * pseudocode:
234
- * function cas(p : pointer to int, old : pointer to int, new : int) returns bool {
235
- * if *p != *old {
236
- * *old = *p
237
- * return false
238
- * }
239
- * *p = new
240
- * return true
241
- * }
242
- *
243
- * @note: In the failure case (where the destination isn't set), the value
244
- * pointed to by expectedCurrentValue is instead updated with the current value.
245
- * This property helps writing concise code for the following incr:
246
- *
247
- * function incr(p : pointer to int, a : int) returns int {
248
- * done = false
249
- * value = *p // This fetch operation need not be atomic.
250
- * while not done {
251
- * done = atomic_cas(p, &value, value + a) // *value gets updated automatically until success
252
- * }
253
- * return value + a
254
- * }
255
- *
256
- * @note: This corresponds to the C11 "atomic_compare_exchange_strong" - it
257
- * always succeeds if the current value is expected, as per the pseudocode
258
- * above; it will not spuriously fail as "atomic_compare_exchange_weak" may.
259
- */
205
+ /** \copydoc core_util_atomic_cas_u8 */
260
206
bool core_util_atomic_cas_u16 (volatile uint16_t * ptr , uint16_t * expectedCurrentValue , uint16_t desiredValue );
261
207
262
- /**
263
- * Atomic compare and set. It compares the contents of a memory location to a
264
- * given value and, only if they are the same, modifies the contents of that
265
- * memory location to a given new value. This is done as a single atomic
266
- * operation. The atomicity guarantees that the new value is calculated based on
267
- * up-to-date information; if the value had been updated by another thread in
268
- * the meantime, the write would fail due to a mismatched expectedCurrentValue.
269
- *
270
- * Refer to https://en.wikipedia.org/wiki/Compare-and-set [which may redirect
271
- * you to the article on compare-and swap].
272
- *
273
- * @param ptr The target memory location.
274
- * @param[in,out] expectedCurrentValue A pointer to some location holding the
275
- * expected current value of the data being set atomically.
276
- * The computed 'desiredValue' should be a function of this current value.
277
- * @note: This is an in-out parameter. In the
278
- * failure case of atomic_cas (where the
279
- * destination isn't set), the pointee of expectedCurrentValue is
280
- * updated with the current value.
281
- * @param[in] desiredValue The new value computed based on '*expectedCurrentValue'.
282
- *
283
- * @return true if the memory location was atomically
284
- * updated with the desired value (after verifying
285
- * that it contained the expectedCurrentValue),
286
- * false otherwise. In the failure case,
287
- * exepctedCurrentValue is updated with the new
288
- * value of the target memory location.
289
- *
290
- * pseudocode:
291
- * function cas(p : pointer to int, old : pointer to int, new : int) returns bool {
292
- * if *p != *old {
293
- * *old = *p
294
- * return false
295
- * }
296
- * *p = new
297
- * return true
298
- * }
299
- *
300
- * @note: In the failure case (where the destination isn't set), the value
301
- * pointed to by expectedCurrentValue is instead updated with the current value.
302
- * This property helps writing concise code for the following incr:
303
- *
304
- * function incr(p : pointer to int, a : int) returns int {
305
- * done = false
306
- * value = *p // This fetch operation need not be atomic.
307
- * while not done {
308
- * done = atomic_cas(p, &value, value + a) // *value gets updated automatically until success
309
- * }
310
- * return value + a
311
- *
312
- * @note: This corresponds to the C11 "atomic_compare_exchange_strong" - it
313
- * always succeeds if the current value is expected, as per the pseudocode
314
- * above; it will not spuriously fail as "atomic_compare_exchange_weak" may.
315
- * }
316
- */
208
+ /** \copydoc core_util_atomic_cas_u8 */
317
209
bool core_util_atomic_cas_u32 (volatile uint32_t * ptr , uint32_t * expectedCurrentValue , uint32_t desiredValue );
318
210
319
- /**
320
- * Atomic compare and set. It compares the contents of a memory location to a
321
- * given value and, only if they are the same, modifies the contents of that
322
- * memory location to a given new value. This is done as a single atomic
323
- * operation. The atomicity guarantees that the new value is calculated based on
324
- * up-to-date information; if the value had been updated by another thread in
325
- * the meantime, the write would fail due to a mismatched expectedCurrentValue.
326
- *
327
- * Refer to https://en.wikipedia.org/wiki/Compare-and-set [which may redirect
328
- * you to the article on compare-and swap].
329
- *
330
- * @param ptr The target memory location.
331
- * @param[in,out] expectedCurrentValue A pointer to some location holding the
332
- * expected current value of the data being set atomically.
333
- * The computed 'desiredValue' should be a function of this current value.
334
- * @note: This is an in-out parameter. In the
335
- * failure case of atomic_cas (where the
336
- * destination isn't set), the pointee of expectedCurrentValue is
337
- * updated with the current value.
338
- * @param[in] desiredValue The new value computed based on '*expectedCurrentValue'.
339
- *
340
- * @return true if the memory location was atomically
341
- * updated with the desired value (after verifying
342
- * that it contained the expectedCurrentValue),
343
- * false otherwise. In the failure case,
344
- * exepctedCurrentValue is updated with the new
345
- * value of the target memory location.
346
- *
347
- * pseudocode:
348
- * function cas(p : pointer to int, old : pointer to int, new : int) returns bool {
349
- * if *p != *old {
350
- * *old = *p
351
- * return false
352
- * }
353
- * *p = new
354
- * return true
355
- * }
356
- *
357
- * @note: In the failure case (where the destination isn't set), the value
358
- * pointed to by expectedCurrentValue is instead updated with the current value.
359
- * This property helps writing concise code for the following incr:
360
- *
361
- * function incr(p : pointer to int, a : int) returns int {
362
- * done = false
363
- * value = *p // This fetch operation need not be atomic.
364
- * while not done {
365
- * done = atomic_cas(p, &value, value + a) // *value gets updated automatically until success
366
- * }
367
- * return value + a
368
- * }
369
- *
370
- * @note: This corresponds to the C11 "atomic_compare_exchange_strong" - it
371
- * always succeeds if the current value is expected, as per the pseudocode
372
- * above; it will not spuriously fail as "atomic_compare_exchange_weak" may.
373
- */
211
+ /** \copydoc core_util_atomic_cas_u8 */
212
+ bool core_util_atomic_cas_u64 (volatile uint64_t * ptr , uint64_t * expectedCurrentValue , uint64_t desiredValue );
213
+
214
+ /** \copydoc core_util_atomic_cas_u8 */
374
215
bool core_util_atomic_cas_ptr (void * volatile * ptr , void * * expectedCurrentValue , void * desiredValue );
375
216
376
217
/**
@@ -409,6 +250,13 @@ MBED_FORCEINLINE uint32_t core_util_atomic_load_u32(const volatile uint32_t *val
409
250
return value ;
410
251
}
411
252
253
+ /**
254
+ * Atomic load.
255
+ * @param valuePtr Target memory location.
256
+ * @return The loaded value.
257
+ */
258
+ uint64_t core_util_atomic_load_u64 (const volatile uint64_t * valuePtr );
259
+
412
260
/**
413
261
* Atomic load.
414
262
* @param valuePtr Target memory location.
@@ -457,6 +305,13 @@ MBED_FORCEINLINE void core_util_atomic_store_u32(volatile uint32_t *valuePtr, ui
457
305
MBED_BARRIER ();
458
306
}
459
307
308
+ /**
309
+ * Atomic store.
310
+ * @param valuePtr Target memory location.
311
+ * @param desiredValue The value to store.
312
+ */
313
+ void core_util_atomic_store_u64 (volatile uint64_t * valuePtr , uint64_t desiredValue );
314
+
460
315
/**
461
316
* Atomic store.
462
317
* @param valuePtr Target memory location.
@@ -493,6 +348,14 @@ uint16_t core_util_atomic_incr_u16(volatile uint16_t *valuePtr, uint16_t delta);
493
348
*/
494
349
uint32_t core_util_atomic_incr_u32 (volatile uint32_t * valuePtr , uint32_t delta );
495
350
351
+ /**
352
+ * Atomic increment.
353
+ * @param valuePtr Target memory location being incremented.
354
+ * @param delta The amount being incremented.
355
+ * @return The new incremented value.
356
+ */
357
+ uint64_t core_util_atomic_incr_u64 (volatile uint64_t * valuePtr , uint64_t delta );
358
+
496
359
/**
497
360
* Atomic increment.
498
361
* @param valuePtr Target memory location being incremented.
@@ -528,6 +391,14 @@ uint16_t core_util_atomic_decr_u16(volatile uint16_t *valuePtr, uint16_t delta);
528
391
*/
529
392
uint32_t core_util_atomic_decr_u32 (volatile uint32_t * valuePtr , uint32_t delta );
530
393
394
+ /**
395
+ * Atomic decrement.
396
+ * @param valuePtr Target memory location being decremented.
397
+ * @param delta The amount being decremented.
398
+ * @return The new decremented value.
399
+ */
400
+ uint64_t core_util_atomic_decr_u64 (volatile uint64_t * valuePtr , uint64_t delta );
401
+
531
402
/**
532
403
* Atomic decrement.
533
404
* @param valuePtr Target memory location being decremented.
0 commit comments