SDL 3.0
SDL_atomic.h
Go to the documentation of this file.
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21
22/**
23 * # CategoryAtomic
24 *
25 * Atomic operations.
26 *
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.
30 *
31 * ***Seriously, here be dragons!***
32 *
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
36 *
37 * There's also lots of good information here:
38 *
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.
46 *
47 * All of the atomic operations that modify memory are full memory barriers.
48 */
49
50#ifndef SDL_atomic_h_
51#define SDL_atomic_h_
52
53#include <SDL3/SDL_stdinc.h>
55
56#include <SDL3/SDL_begin_code.h>
57
58/* Set up for C function definitions, even when using C++ */
59#ifdef __cplusplus
60extern "C" {
61#endif
62
63/**
64 * An atomic spinlock.
65 *
66 * The atomic locks are efficient spinlocks using CPU instructions, but are
67 * vulnerable to starvation and can spin forever if a thread holding a lock
68 * has been terminated. For this reason you should minimize the code executed
69 * inside an atomic lock and never do expensive things like API or system
70 * calls while holding them.
71 *
72 * They are also vulnerable to starvation if the thread holding the lock is
73 * lower priority than other threads and doesn't get scheduled. In general you
74 * should use mutexes instead, since they have better performance and
75 * contention behavior.
76 *
77 * The atomic locks are not safe to lock recursively.
78 *
79 * Porting Note: The spin lock functions and type are required and can not be
80 * emulated because they are used in the atomic emulation code.
81 */
82typedef int SDL_SpinLock;
83
84/**
85 * Try to lock a spin lock by setting it to a non-zero value.
86 *
87 * ***Please note that spinlocks are dangerous if you don't know what you're
88 * doing. Please be careful using any sort of spinlock!***
89 *
90 * \param lock a pointer to a lock variable.
91 * \returns true if the lock succeeded, false if the lock is already held.
92 *
93 * \threadsafety It is safe to call this function from any thread.
94 *
95 * \since This function is available since SDL 3.1.3.
96 *
97 * \sa SDL_LockSpinlock
98 * \sa SDL_UnlockSpinlock
99 */
100extern SDL_DECLSPEC bool SDLCALL SDL_TryLockSpinlock(SDL_SpinLock *lock);
101
102/**
103 * Lock a spin lock by setting it to a non-zero value.
104 *
105 * ***Please note that spinlocks are dangerous if you don't know what you're
106 * doing. Please be careful using any sort of spinlock!***
107 *
108 * \param lock a pointer to a lock variable.
109 *
110 * \threadsafety It is safe to call this function from any thread.
111 *
112 * \since This function is available since SDL 3.1.3.
113 *
114 * \sa SDL_TryLockSpinlock
115 * \sa SDL_UnlockSpinlock
116 */
117extern SDL_DECLSPEC void SDLCALL SDL_LockSpinlock(SDL_SpinLock *lock);
118
119/**
120 * Unlock a spin lock by setting it to 0.
121 *
122 * Always returns immediately.
123 *
124 * ***Please note that spinlocks are dangerous if you don't know what you're
125 * doing. Please be careful using any sort of spinlock!***
126 *
127 * \param lock a pointer to a lock variable.
128 *
129 * \threadsafety It is safe to call this function from any thread.
130 *
131 * \since This function is available since SDL 3.1.3.
132 *
133 * \sa SDL_LockSpinlock
134 * \sa SDL_TryLockSpinlock
135 */
136extern SDL_DECLSPEC void SDLCALL SDL_UnlockSpinlock(SDL_SpinLock *lock);
137
138
139#ifdef SDL_WIKI_DOCUMENTATION_SECTION
140
141/**
142 * Mark a compiler barrier.
143 *
144 * A compiler barrier prevents the compiler from reordering reads and writes
145 * to globally visible variables across the call.
146 *
147 * This macro only prevents the compiler from reordering reads and writes, it
148 * does not prevent the CPU from reordering reads and writes. However, all of
149 * the atomic operations that modify memory are full memory barriers.
150 *
151 * \threadsafety Obviously this macro is safe to use from any thread at any
152 * time, but if you find yourself needing this, you are probably
153 * dealing with some very sensitive code; be careful!
154 *
155 * \since This macro is available since SDL 3.1.3.
156 */
157#define SDL_CompilerBarrier() DoCompilerSpecificReadWriteBarrier()
158#elif defined(_MSC_VER) && (_MSC_VER > 1200) && !defined(__clang__)
159void _ReadWriteBarrier(void);
160#pragma intrinsic(_ReadWriteBarrier)
161#define SDL_CompilerBarrier() _ReadWriteBarrier()
162#elif (defined(__GNUC__) && !defined(SDL_PLATFORM_EMSCRIPTEN)) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x5120))
163/* This is correct for all CPUs when using GCC or Solaris Studio 12.1+. */
164#define SDL_CompilerBarrier() __asm__ __volatile__ ("" : : : "memory")
165#elif defined(__WATCOMC__)
166extern __inline void SDL_CompilerBarrier(void);
167#pragma aux SDL_CompilerBarrier = "" parm [] modify exact [];
168#else
169#define SDL_CompilerBarrier() \
170{ SDL_SpinLock _tmp = 0; SDL_LockSpinlock(&_tmp); SDL_UnlockSpinlock(&_tmp); }
171#endif
172
173/**
174 * Insert a memory release barrier.
175 *
176 * Memory barriers are designed to prevent reads and writes from being
177 * reordered by the compiler and being seen out of order on multi-core CPUs.
178 *
179 * A typical pattern would be for thread A to write some data and a flag, and
180 * for thread B to read the flag and get the data. In this case you would
181 * insert a release barrier between writing the data and the flag,
182 * guaranteeing that the data write completes no later than the flag is
183 * written, and you would insert an acquire barrier between reading the flag
184 * and reading the data, to ensure that all the reads associated with the flag
185 * have completed.
186 *
187 * In this pattern you should always see a release barrier paired with an
188 * acquire barrier and you should gate the data reads/writes with a single
189 * flag variable.
190 *
191 * For more information on these semantics, take a look at the blog post:
192 * http://preshing.com/20120913/acquire-and-release-semantics
193 *
194 * \threadsafety Obviously this macro is safe to use from any thread at any
195 * time, but if you find yourself needing this, you are probably
196 * dealing with some very sensitive code; be careful!
197 *
198 * \since This function is available since SDL 3.1.3.
199 */
200extern SDL_DECLSPEC void SDLCALL SDL_MemoryBarrierReleaseFunction(void);
201
202/**
203 * Insert a memory acquire barrier.
204 *
205 * Please refer to SDL_MemoryBarrierReleaseFunction for the details!
206 *
207 * \threadsafety Obviously this function is safe to use from any thread at any
208 * time, but if you find yourself needing this, you are probably
209 * dealing with some very sensitive code; be careful!
210 *
211 * \since This function is available since SDL 3.1.3.
212 *
213 * \sa SDL_MemoryBarrierReleaseFunction
214 */
215extern SDL_DECLSPEC void SDLCALL SDL_MemoryBarrierAcquireFunction(void);
216
217/* !!! FIXME: this should have documentation! */
218#if defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__))
219#define SDL_MemoryBarrierRelease() __asm__ __volatile__ ("lwsync" : : : "memory")
220#define SDL_MemoryBarrierAcquire() __asm__ __volatile__ ("lwsync" : : : "memory")
221#elif defined(__GNUC__) && defined(__aarch64__)
222#define SDL_MemoryBarrierRelease() __asm__ __volatile__ ("dmb ish" : : : "memory")
223#define SDL_MemoryBarrierAcquire() __asm__ __volatile__ ("dmb ish" : : : "memory")
224#elif defined(__GNUC__) && defined(__arm__)
225#if 0 /* defined(SDL_PLATFORM_LINUX) || defined(SDL_PLATFORM_ANDROID) */
226/* Information from:
227 https://chromium.googlesource.com/chromium/chromium/+/trunk/base/atomicops_internals_arm_gcc.h#19
228
229 The Linux kernel provides a helper function which provides the right code for a memory barrier,
230 hard-coded at address 0xffff0fa0
231*/
232typedef void (*SDL_KernelMemoryBarrierFunc)();
233#define SDL_MemoryBarrierRelease() ((SDL_KernelMemoryBarrierFunc)0xffff0fa0)()
234#define SDL_MemoryBarrierAcquire() ((SDL_KernelMemoryBarrierFunc)0xffff0fa0)()
235#else
236#if defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7EM__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) || defined(__ARM_ARCH_8A__)
237#define SDL_MemoryBarrierRelease() __asm__ __volatile__ ("dmb ish" : : : "memory")
238#define SDL_MemoryBarrierAcquire() __asm__ __volatile__ ("dmb ish" : : : "memory")
239#elif defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6T2__) || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__)
240#ifdef __thumb__
241/* The mcr instruction isn't available in thumb mode, use real functions */
242#define SDL_MEMORY_BARRIER_USES_FUNCTION
243#define SDL_MemoryBarrierRelease() SDL_MemoryBarrierReleaseFunction()
244#define SDL_MemoryBarrierAcquire() SDL_MemoryBarrierAcquireFunction()
245#else
246#define SDL_MemoryBarrierRelease() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 5" : : "r"(0) : "memory")
247#define SDL_MemoryBarrierAcquire() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 5" : : "r"(0) : "memory")
248#endif /* __thumb__ */
249#else
250#define SDL_MemoryBarrierRelease() __asm__ __volatile__ ("" : : : "memory")
251#define SDL_MemoryBarrierAcquire() __asm__ __volatile__ ("" : : : "memory")
252#endif /* SDL_PLATFORM_LINUX || SDL_PLATFORM_ANDROID */
253#endif /* __GNUC__ && __arm__ */
254#else
255#if (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x5120))
256/* This is correct for all CPUs on Solaris when using Solaris Studio 12.1+. */
257#include <mbarrier.h>
258#define SDL_MemoryBarrierRelease() __machine_rel_barrier()
259#define SDL_MemoryBarrierAcquire() __machine_acq_barrier()
260#else
261/* This is correct for the x86 and x64 CPUs, and we'll expand this over time. */
262#define SDL_MemoryBarrierRelease() SDL_CompilerBarrier()
263#define SDL_MemoryBarrierAcquire() SDL_CompilerBarrier()
264#endif
265#endif
266
267/* "REP NOP" is PAUSE, coded for tools that don't know it by that name. */
268#ifdef SDL_WIKI_DOCUMENTATION_SECTION
269
270/**
271 * A macro to insert a CPU-specific "pause" instruction into the program.
272 *
273 * This can be useful in busy-wait loops, as it serves as a hint to the CPU as
274 * to the program's intent; some CPUs can use this to do more efficient
275 * processing. On some platforms, this doesn't do anything, so using this
276 * macro might just be a harmless no-op.
277 *
278 * Note that if you are busy-waiting, there are often more-efficient
279 * approaches with other synchronization primitives: mutexes, semaphores,
280 * condition variables, etc.
281 *
282 * \threadsafety This macro is safe to use from any thread.
283 *
284 * \since This macro is available since SDL 3.1.3.
285 */
286#define SDL_CPUPauseInstruction() DoACPUPauseInACompilerAndArchitectureSpecificWay
287#elif (defined(__GNUC__) || defined(__clang__)) && (defined(__i386__) || defined(__x86_64__))
288 #define SDL_CPUPauseInstruction() __asm__ __volatile__("pause\n") /* Some assemblers can't do REP NOP, so go with PAUSE. */
289#elif (defined(__arm__) && defined(__ARM_ARCH) && __ARM_ARCH >= 7) || defined(__aarch64__)
290 #define SDL_CPUPauseInstruction() __asm__ __volatile__("yield" ::: "memory")
291#elif (defined(__powerpc__) || defined(__powerpc64__))
292 #define SDL_CPUPauseInstruction() __asm__ __volatile__("or 27,27,27");
293#elif (defined(__riscv) && __riscv_xlen == 64)
294 #define SDL_CPUPauseInstruction() __asm__ __volatile__(".insn i 0x0F, 0, x0, x0, 0x010");
295#elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64))
296 #define SDL_CPUPauseInstruction() _mm_pause() /* this is actually "rep nop" and not a SIMD instruction. No inline asm in MSVC x86-64! */
297#elif defined(_MSC_VER) && (defined(_M_ARM) || defined(_M_ARM64))
298 #define SDL_CPUPauseInstruction() __yield()
299#elif defined(__WATCOMC__) && defined(__386__)
300 extern __inline void SDL_CPUPauseInstruction(void);
301 #pragma aux SDL_CPUPauseInstruction = ".686p" ".xmm2" "pause"
302#else
303 #define SDL_CPUPauseInstruction()
304#endif
305
306
307/**
308 * A type representing an atomic integer value.
309 *
310 * This can be used to manage a value that is synchronized across multiple
311 * CPUs without a race condition; when an app sets a value with
312 * SDL_SetAtomicInt all other threads, regardless of the CPU it is running on,
313 * will see that value when retrieved with SDL_GetAtomicInt, regardless of CPU
314 * caches, etc.
315 *
316 * This is also useful for atomic compare-and-swap operations: a thread can
317 * change the value as long as its current value matches expectations. When
318 * done in a loop, one can guarantee data consistency across threads without a
319 * lock (but the usual warnings apply: if you don't know what you're doing, or
320 * you don't do it carefully, you can confidently cause any number of
321 * disasters with this, so in most cases, you _should_ use a mutex instead of
322 * this!).
323 *
324 * This is a struct so people don't accidentally use numeric operations on it
325 * directly. You have to use SDL atomic functions.
326 *
327 * \since This struct is available since SDL 3.1.3.
328 *
329 * \sa SDL_CompareAndSwapAtomicInt
330 * \sa SDL_GetAtomicInt
331 * \sa SDL_SetAtomicInt
332 * \sa SDL_AddAtomicInt
333 */
334typedef struct SDL_AtomicInt { int value; } SDL_AtomicInt;
335
336/**
337 * Set an atomic variable to a new value if it is currently an old value.
338 *
339 * ***Note: If you don't know what this function is for, you shouldn't use
340 * it!***
341 *
342 * \param a a pointer to an SDL_AtomicInt variable to be modified.
343 * \param oldval the old value.
344 * \param newval the new value.
345 * \returns true if the atomic variable was set, false otherwise.
346 *
347 * \threadsafety It is safe to call this function from any thread.
348 *
349 * \since This function is available since SDL 3.1.3.
350 *
351 * \sa SDL_GetAtomicInt
352 * \sa SDL_SetAtomicInt
353 */
354extern SDL_DECLSPEC bool SDLCALL SDL_CompareAndSwapAtomicInt(SDL_AtomicInt *a, int oldval, int newval);
355
356/**
357 * Set an atomic variable to a value.
358 *
359 * This function also acts as a full memory barrier.
360 *
361 * ***Note: If you don't know what this function is for, you shouldn't use
362 * it!***
363 *
364 * \param a a pointer to an SDL_AtomicInt variable to be modified.
365 * \param v the desired value.
366 * \returns the previous value of the atomic variable.
367 *
368 * \threadsafety It is safe to call this function from any thread.
369 *
370 * \since This function is available since SDL 3.1.3.
371 *
372 * \sa SDL_GetAtomicInt
373 */
374extern SDL_DECLSPEC int SDLCALL SDL_SetAtomicInt(SDL_AtomicInt *a, int v);
375
376/**
377 * Get the value of an atomic variable.
378 *
379 * ***Note: If you don't know what this function is for, you shouldn't use
380 * it!***
381 *
382 * \param a a pointer to an SDL_AtomicInt variable.
383 * \returns the current value of an atomic variable.
384 *
385 * \threadsafety It is safe to call this function from any thread.
386 *
387 * \since This function is available since SDL 3.1.3.
388 *
389 * \sa SDL_SetAtomicInt
390 */
391extern SDL_DECLSPEC int SDLCALL SDL_GetAtomicInt(SDL_AtomicInt *a);
392
393/**
394 * Add to an atomic variable.
395 *
396 * This function also acts as a full memory barrier.
397 *
398 * ***Note: If you don't know what this function is for, you shouldn't use
399 * it!***
400 *
401 * \param a a pointer to an SDL_AtomicInt variable to be modified.
402 * \param v the desired value to add.
403 * \returns the previous value of the atomic variable.
404 *
405 * \threadsafety It is safe to call this function from any thread.
406 *
407 * \since This function is available since SDL 3.1.3.
408 *
409 * \sa SDL_AtomicDecRef
410 * \sa SDL_AtomicIncRef
411 */
412extern SDL_DECLSPEC int SDLCALL SDL_AddAtomicInt(SDL_AtomicInt *a, int v);
413
414#ifndef SDL_AtomicIncRef
415
416/**
417 * Increment an atomic variable used as a reference count.
418 *
419 * ***Note: If you don't know what this macro is for, you shouldn't use it!***
420 *
421 * \param a a pointer to an SDL_AtomicInt to increment.
422 * \returns the previous value of the atomic variable.
423 *
424 * \threadsafety It is safe to call this macro from any thread.
425 *
426 * \since This macro is available since SDL 3.1.3.
427 *
428 * \sa SDL_AtomicDecRef
429 */
430#define SDL_AtomicIncRef(a) SDL_AddAtomicInt(a, 1)
431#endif
432
433#ifndef SDL_AtomicDecRef
434
435/**
436 * Decrement an atomic variable used as a reference count.
437 *
438 * ***Note: If you don't know what this macro is for, you shouldn't use it!***
439 *
440 * \param a a pointer to an SDL_AtomicInt to increment.
441 * \returns true if the variable reached zero after decrementing, false
442 * otherwise.
443 *
444 * \threadsafety It is safe to call this macro from any thread.
445 *
446 * \since This macro is available since SDL 3.1.3.
447 *
448 * \sa SDL_AtomicIncRef
449 */
450#define SDL_AtomicDecRef(a) (SDL_AddAtomicInt(a, -1) == 1)
451#endif
452
453/**
454 * A type representing an atomic unsigned 32-bit value.
455 *
456 * This can be used to manage a value that is synchronized across multiple
457 * CPUs without a race condition; when an app sets a value with
458 * SDL_SetAtomicU32 all other threads, regardless of the CPU it is running on,
459 * will see that value when retrieved with SDL_GetAtomicU32, regardless of CPU
460 * caches, etc.
461 *
462 * This is also useful for atomic compare-and-swap operations: a thread can
463 * change the value as long as its current value matches expectations. When
464 * done in a loop, one can guarantee data consistency across threads without a
465 * lock (but the usual warnings apply: if you don't know what you're doing, or
466 * you don't do it carefully, you can confidently cause any number of
467 * disasters with this, so in most cases, you _should_ use a mutex instead of
468 * this!).
469 *
470 * This is a struct so people don't accidentally use numeric operations on it
471 * directly. You have to use SDL atomic functions.
472 *
473 * \since This struct is available since SDL 3.1.3.
474 *
475 * \sa SDL_CompareAndSwapAtomicU32
476 * \sa SDL_GetAtomicU32
477 * \sa SDL_SetAtomicU32
478 */
480
481/**
482 * Set an atomic variable to a new value if it is currently an old value.
483 *
484 * ***Note: If you don't know what this function is for, you shouldn't use
485 * it!***
486 *
487 * \param a a pointer to an SDL_AtomicU32 variable to be modified.
488 * \param oldval the old value.
489 * \param newval the new value.
490 * \returns true if the atomic variable was set, false otherwise.
491 *
492 * \threadsafety It is safe to call this function from any thread.
493 *
494 * \since This function is available since SDL 3.1.3.
495 *
496 * \sa SDL_GetAtomicU32
497 * \sa SDL_SetAtomicU32
498 */
499extern SDL_DECLSPEC bool SDLCALL SDL_CompareAndSwapAtomicU32(SDL_AtomicU32 *a, Uint32 oldval, Uint32 newval);
500
501/**
502 * Set an atomic variable to a value.
503 *
504 * This function also acts as a full memory barrier.
505 *
506 * ***Note: If you don't know what this function is for, you shouldn't use
507 * it!***
508 *
509 * \param a a pointer to an SDL_AtomicU32 variable to be modified.
510 * \param v the desired value.
511 * \returns the previous value of the atomic variable.
512 *
513 * \threadsafety It is safe to call this function from any thread.
514 *
515 * \since This function is available since SDL 3.1.3.
516 *
517 * \sa SDL_GetAtomicU32
518 */
519extern SDL_DECLSPEC Uint32 SDLCALL SDL_SetAtomicU32(SDL_AtomicU32 *a, Uint32 v);
520
521/**
522 * Get the value of an atomic variable.
523 *
524 * ***Note: If you don't know what this function is for, you shouldn't use
525 * it!***
526 *
527 * \param a a pointer to an SDL_AtomicU32 variable.
528 * \returns the current value of an atomic variable.
529 *
530 * \threadsafety It is safe to call this function from any thread.
531 *
532 * \since This function is available since SDL 3.1.3.
533 *
534 * \sa SDL_SetAtomicU32
535 */
536extern SDL_DECLSPEC Uint32 SDLCALL SDL_GetAtomicU32(SDL_AtomicU32 *a);
537
538/**
539 * Set a pointer to a new value if it is currently an old value.
540 *
541 * ***Note: If you don't know what this function is for, you shouldn't use
542 * it!***
543 *
544 * \param a a pointer to a pointer.
545 * \param oldval the old pointer value.
546 * \param newval the new pointer value.
547 * \returns true if the pointer was set, false otherwise.
548 *
549 * \threadsafety It is safe to call this function from any thread.
550 *
551 * \since This function is available since SDL 3.1.3.
552 *
553 * \sa SDL_CompareAndSwapAtomicInt
554 * \sa SDL_GetAtomicPointer
555 * \sa SDL_SetAtomicPointer
556 */
557extern SDL_DECLSPEC bool SDLCALL SDL_CompareAndSwapAtomicPointer(void **a, void *oldval, void *newval);
558
559/**
560 * Set a pointer to a value atomically.
561 *
562 * ***Note: If you don't know what this function is for, you shouldn't use
563 * it!***
564 *
565 * \param a a pointer to a pointer.
566 * \param v the desired pointer value.
567 * \returns the previous value of the pointer.
568 *
569 * \threadsafety It is safe to call this function from any thread.
570 *
571 * \since This function is available since SDL 3.1.3.
572 *
573 * \sa SDL_CompareAndSwapAtomicPointer
574 * \sa SDL_GetAtomicPointer
575 */
576extern SDL_DECLSPEC void * SDLCALL SDL_SetAtomicPointer(void **a, void *v);
577
578/**
579 * Get the value of a pointer atomically.
580 *
581 * ***Note: If you don't know what this function is for, you shouldn't use
582 * it!***
583 *
584 * \param a a pointer to a pointer.
585 * \returns the current value of a pointer.
586 *
587 * \threadsafety It is safe to call this function from any thread.
588 *
589 * \since This function is available since SDL 3.1.3.
590 *
591 * \sa SDL_CompareAndSwapAtomicPointer
592 * \sa SDL_SetAtomicPointer
593 */
594extern SDL_DECLSPEC void * SDLCALL SDL_GetAtomicPointer(void **a);
595
596/* Ends C function definitions when using C++ */
597#ifdef __cplusplus
598}
599#endif
600
601#include <SDL3/SDL_close_code.h>
602
603#endif /* SDL_atomic_h_ */
Uint32 SDL_GetAtomicU32(SDL_AtomicU32 *a)
void SDL_MemoryBarrierAcquireFunction(void)
bool SDL_CompareAndSwapAtomicInt(SDL_AtomicInt *a, int oldval, int newval)
void * SDL_GetAtomicPointer(void **a)
#define SDL_CompilerBarrier()
Definition SDL_atomic.h:169
bool SDL_CompareAndSwapAtomicPointer(void **a, void *oldval, void *newval)
void SDL_MemoryBarrierReleaseFunction(void)
int SDL_SpinLock
Definition SDL_atomic.h:82
#define SDL_CPUPauseInstruction()
Definition SDL_atomic.h:303
int SDL_SetAtomicInt(SDL_AtomicInt *a, int v)
void SDL_LockSpinlock(SDL_SpinLock *lock)
bool SDL_CompareAndSwapAtomicU32(SDL_AtomicU32 *a, Uint32 oldval, Uint32 newval)
void SDL_UnlockSpinlock(SDL_SpinLock *lock)
Uint32 SDL_SetAtomicU32(SDL_AtomicU32 *a, Uint32 v)
int SDL_AddAtomicInt(SDL_AtomicInt *a, int v)
bool SDL_TryLockSpinlock(SDL_SpinLock *lock)
void * SDL_SetAtomicPointer(void **a, void *v)
int SDL_GetAtomicInt(SDL_AtomicInt *a)
uint32_t Uint32
Definition SDL_stdinc.h:373