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