SDL
2.0
|
Go to the source code of this file.
Macros | |
#define | EMULATE_CAS 1 |
Functions | |
static SDL_INLINE void | enterLock (void *a) |
static SDL_INLINE void | leaveLock (void *a) |
SDL_bool | SDL_AtomicCAS (SDL_atomic_t *a, int oldval, int newval) |
Set an atomic variable to a new value if it is currently an old value. More... | |
SDL_bool | SDL_AtomicCASPtr (void **a, void *oldval, void *newval) |
Set a pointer to a new value if it is currently an old value. More... | |
int | SDL_AtomicSet (SDL_atomic_t *a, int v) |
Set an atomic variable to a value. More... | |
void * | SDL_AtomicSetPtr (void **a, void *v) |
Set a pointer to a value atomically. More... | |
int | SDL_AtomicAdd (SDL_atomic_t *a, int v) |
Add to an atomic variable. More... | |
int | SDL_AtomicGet (SDL_atomic_t *a) |
Get the value of an atomic variable. More... | |
void * | SDL_AtomicGetPtr (void **a) |
Get the value of a pointer atomically. More... | |
void | SDL_MemoryBarrierReleaseFunction (void) |
void | SDL_MemoryBarrierAcquireFunction (void) |
Variables | |
static SDL_SpinLock | locks [32] |
#define EMULATE_CAS 1 |
Definition at line 104 of file SDL_atomic.c.
|
static |
Definition at line 111 of file SDL_atomic.c.
References locks, SDL_AtomicLock, and SDL_INLINE.
Referenced by SDL_AtomicCAS(), and SDL_AtomicCASPtr().
|
static |
Definition at line 119 of file SDL_atomic.c.
References locks, and SDL_AtomicUnlock.
Referenced by SDL_AtomicCAS(), and SDL_AtomicCASPtr().
int SDL_AtomicAdd | ( | SDL_atomic_t * | a, |
int | v | ||
) |
Add to an atomic variable.
Definition at line 237 of file SDL_atomic.c.
References SDL_AtomicCAS(), and SDL_atomic_t::value.
SDL_bool SDL_AtomicCAS | ( | SDL_atomic_t * | a, |
int | oldval, | ||
int | newval | ||
) |
Set an atomic variable to a new value if it is currently an old value.
Definition at line 129 of file SDL_atomic.c.
References enterLock(), leaveLock(), retval, SDL_FALSE, SDL_TRUE, and SDL_atomic_t::value.
Referenced by SDL_AtomicAdd(), SDL_AtomicGet(), and SDL_AtomicSet().
Set a pointer to a new value if it is currently an old value.
Definition at line 160 of file SDL_atomic.c.
References enterLock(), leaveLock(), retval, SDL_FALSE, and SDL_TRUE.
Referenced by SDL_AtomicGetPtr(), and SDL_AtomicSetPtr().
int SDL_AtomicGet | ( | SDL_atomic_t * | a | ) |
Get the value of an atomic variable.
Definition at line 264 of file SDL_atomic.c.
References SDL_AtomicCAS(), and SDL_atomic_t::value.
Get the value of a pointer atomically.
Definition at line 278 of file SDL_atomic.c.
References SDL_AtomicCASPtr().
int SDL_AtomicSet | ( | SDL_atomic_t * | a, |
int | v | ||
) |
Set an atomic variable to a value.
Definition at line 193 of file SDL_atomic.c.
References SDL_AtomicCAS(), and SDL_atomic_t::value.
Set a pointer to a value atomically.
Definition at line 215 of file SDL_atomic.c.
References SDL_AtomicCASPtr().
Memory barriers are designed to prevent reads and writes from being reordered by the compiler and being seen out of order on multi-core CPUs.
A typical pattern would be for thread A to write some data and a flag, and for thread B to read the flag and get the data. In this case you would insert a release barrier between writing the data and the flag, guaranteeing that the data write completes no later than the flag is written, and you would insert an acquire barrier between reading the flag and reading the data, to ensure that all the reads associated with the flag have completed.
In this pattern you should always see a release barrier paired with an acquire barrier and you should gate the data reads/writes with a single flag variable.
For more information on these semantics, take a look at the blog post: http://preshing.com/20120913/acquire-and-release-semantics
Definition at line 292 of file SDL_atomic.c.
References SDL_MemoryBarrierRelease.
|
static |
Definition at line 108 of file SDL_atomic.c.
Referenced by enterLock(), and leaveLock().