1
1
/*
2
2
Simple DirectMedia Layer
3
- Copyright (C) 1997-2024 Sam Lantinga <[email protected] >
3
+ Copyright (C) 1997-2025 Sam Lantinga <[email protected] >
4
4
5
5
This software is provided 'as-is', without any express or implied
6
6
warranty. In no event will the authors be held liable for any damages
20
20
*/
21
21
22
22
/**
23
- * \file SDL_atomic.h
23
+ * # CategoryAtomic
24
24
*
25
25
* Atomic operations.
26
26
*
27
- * IMPORTANT:
28
- * If you are not an expert in concurrent lockless programming, you should
29
- * only be using the atomic lock and reference counting functions in this
30
- * file. In all other cases you should be protecting your data structures
31
- * with full mutexes.
27
+ * IMPORTANT: If you are not an expert in concurrent lockless programming, you
28
+ * should not be using any functions in this file. You should be protecting
29
+ * your data structures with full mutexes instead.
32
30
*
33
- * The list of "safe" functions to use are:
34
- * SDL_AtomicLock()
35
- * SDL_AtomicUnlock()
36
- * SDL_AtomicIncRef()
37
- * SDL_AtomicDecRef()
31
+ * ***Seriously, here be dragons!***
38
32
*
39
- * Seriously, here be dragons!
40
- * ^^^^^^^^^^^^^^^^^^^^^^^^^^^
41
- *
42
- * You can find out a little more about lockless programming and the
43
- * subtle issues that can arise here:
44
- * http://msdn.microsoft.com/en-us/library/ee418650%28v=vs.85%29.aspx
33
+ * You can find out a little more about lockless programming and the subtle
34
+ * issues that can arise here:
35
+ * https://learn.microsoft.com/en-us/windows/win32/dxtecharts/lockless-programming
45
36
*
46
37
* There's also lots of good information here:
47
- * http://www.1024cores.net/home/lock-free-algorithms
48
- * http://preshing.com/
49
38
*
50
- * These operations may or may not actually be implemented using
51
- * processor specific atomic operations. When possible they are
52
- * implemented as true processor specific atomic operations. When that
53
- * is not possible the are implemented using locks that *do* use the
54
- * available atomic operations.
39
+ * - https://www.1024cores.net/home/lock-free-algorithms
40
+ * - https://preshing.com/
41
+ *
42
+ * These operations may or may not actually be implemented using processor
43
+ * specific atomic operations. When possible they are implemented as true
44
+ * processor specific atomic operations. When that is not possible the are
45
+ * implemented using locks that *do* use the available atomic operations.
55
46
*
56
47
* All of the atomic operations that modify memory are full memory barriers.
57
48
*/
@@ -94,7 +85,7 @@ typedef int SDL_SpinLock;
94
85
* ***Please note that spinlocks are dangerous if you don't know what you're
95
86
* doing. Please be careful using any sort of spinlock!***
96
87
*
97
- * \param lock a pointer to a lock variable
88
+ * \param lock a pointer to a lock variable.
98
89
* \returns SDL_TRUE if the lock succeeded, SDL_FALSE if the lock is already
99
90
* held.
100
91
*
@@ -111,7 +102,7 @@ extern DECLSPEC SDL_bool SDLCALL SDL_AtomicTryLock(SDL_SpinLock *lock);
111
102
* ***Please note that spinlocks are dangerous if you don't know what you're
112
103
* doing. Please be careful using any sort of spinlock!***
113
104
*
114
- * \param lock a pointer to a lock variable
105
+ * \param lock a pointer to a lock variable.
115
106
*
116
107
* \since This function is available since SDL 2.0.0.
117
108
*
@@ -128,7 +119,7 @@ extern DECLSPEC void SDLCALL SDL_AtomicLock(SDL_SpinLock *lock);
128
119
* ***Please note that spinlocks are dangerous if you don't know what you're
129
120
* doing. Please be careful using any sort of spinlock!***
130
121
*
131
- * \param lock a pointer to a lock variable
122
+ * \param lock a pointer to a lock variable.
132
123
*
133
124
* \since This function is available since SDL 2.0.0.
134
125
*
@@ -257,20 +248,23 @@ typedef void (*SDL_KernelMemoryBarrierFunc)();
257
248
258
249
259
250
/**
260
- * \brief A type representing an atomic integer value. It is a struct
261
- * so people don't accidentally use numeric operations on it.
251
+ * A type representing an atomic integer value.
252
+ *
253
+ * It is a struct so people don't accidentally use numeric operations on it.
262
254
*/
263
- typedef struct { int value ; } SDL_atomic_t ;
255
+ typedef struct SDL_atomic_t {
256
+ int value ;
257
+ } SDL_atomic_t ;
264
258
265
259
/**
266
260
* Set an atomic variable to a new value if it is currently an old value.
267
261
*
268
262
* ***Note: If you don't know what this function is for, you shouldn't use
269
263
* it!***
270
264
*
271
- * \param a a pointer to an SDL_atomic_t variable to be modified
272
- * \param oldval the old value
273
- * \param newval the new value
265
+ * \param a a pointer to an SDL_atomic_t variable to be modified.
266
+ * \param oldval the old value.
267
+ * \param newval the new value.
274
268
* \returns SDL_TRUE if the atomic variable was set, SDL_FALSE otherwise.
275
269
*
276
270
* \since This function is available since SDL 2.0.0.
@@ -289,8 +283,8 @@ extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCAS(SDL_atomic_t *a, int oldval, int
289
283
* ***Note: If you don't know what this function is for, you shouldn't use
290
284
* it!***
291
285
*
292
- * \param a a pointer to an SDL_atomic_t variable to be modified
293
- * \param v the desired value
286
+ * \param a a pointer to an SDL_atomic_t variable to be modified.
287
+ * \param v the desired value.
294
288
* \returns the previous value of the atomic variable.
295
289
*
296
290
* \since This function is available since SDL 2.0.2.
@@ -305,7 +299,7 @@ extern DECLSPEC int SDLCALL SDL_AtomicSet(SDL_atomic_t *a, int v);
305
299
* ***Note: If you don't know what this function is for, you shouldn't use
306
300
* it!***
307
301
*
308
- * \param a a pointer to an SDL_atomic_t variable
302
+ * \param a a pointer to an SDL_atomic_t variable.
309
303
* \returns the current value of an atomic variable.
310
304
*
311
305
* \since This function is available since SDL 2.0.2.
@@ -322,8 +316,8 @@ extern DECLSPEC int SDLCALL SDL_AtomicGet(SDL_atomic_t *a);
322
316
* ***Note: If you don't know what this function is for, you shouldn't use
323
317
* it!***
324
318
*
325
- * \param a a pointer to an SDL_atomic_t variable to be modified
326
- * \param v the desired value to add
319
+ * \param a a pointer to an SDL_atomic_t variable to be modified.
320
+ * \param v the desired value to add.
327
321
* \returns the previous value of the atomic variable.
328
322
*
329
323
* \since This function is available since SDL 2.0.2.
@@ -356,9 +350,9 @@ extern DECLSPEC int SDLCALL SDL_AtomicAdd(SDL_atomic_t *a, int v);
356
350
* ***Note: If you don't know what this function is for, you shouldn't use
357
351
* it!***
358
352
*
359
- * \param a a pointer to a pointer
360
- * \param oldval the old pointer value
361
- * \param newval the new pointer value
353
+ * \param a a pointer to a pointer.
354
+ * \param oldval the old pointer value.
355
+ * \param newval the new pointer value.
362
356
* \returns SDL_TRUE if the pointer was set, SDL_FALSE otherwise.
363
357
*
364
358
* \since This function is available since SDL 2.0.0.
@@ -375,8 +369,8 @@ extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCASPtr(void **a, void *oldval, void *
375
369
* ***Note: If you don't know what this function is for, you shouldn't use
376
370
* it!***
377
371
*
378
- * \param a a pointer to a pointer
379
- * \param v the desired pointer value
372
+ * \param a a pointer to a pointer.
373
+ * \param v the desired pointer value.
380
374
* \returns the previous value of the pointer.
381
375
*
382
376
* \since This function is available since SDL 2.0.2.
@@ -392,7 +386,7 @@ extern DECLSPEC void* SDLCALL SDL_AtomicSetPtr(void **a, void* v);
392
386
* ***Note: If you don't know what this function is for, you shouldn't use
393
387
* it!***
394
388
*
395
- * \param a a pointer to a pointer
389
+ * \param a a pointer to a pointer.
396
390
* \returns the current value of a pointer.
397
391
*
398
392
* \since This function is available since SDL 2.0.2.
0 commit comments