mirror of
https://github.com/Relintai/sdl2_frt.git
synced 2024-12-16 11:06:49 +01:00
Use GCC's atomic loads in SDL_AtomicGet and SDL_AtomicGetPtr
This fixes errors reported by address sanitizer, and generates simpler code on x86 architectures.
This commit is contained in:
parent
266816b4aa
commit
1dc9ae5c1e
@ -211,21 +211,29 @@ SDL_AtomicAdd(SDL_atomic_t *a, int v)
|
|||||||
int
|
int
|
||||||
SDL_AtomicGet(SDL_atomic_t *a)
|
SDL_AtomicGet(SDL_atomic_t *a)
|
||||||
{
|
{
|
||||||
|
#ifdef HAVE_GCC_ATOMICS
|
||||||
|
return __atomic_load_n(&a->value, __ATOMIC_SEQ_CST);
|
||||||
|
#else
|
||||||
int value;
|
int value;
|
||||||
do {
|
do {
|
||||||
value = a->value;
|
value = a->value;
|
||||||
} while (!SDL_AtomicCAS(a, value, value));
|
} while (!SDL_AtomicCAS(a, value, value));
|
||||||
return value;
|
return value;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void *
|
void *
|
||||||
SDL_AtomicGetPtr(void **a)
|
SDL_AtomicGetPtr(void **a)
|
||||||
{
|
{
|
||||||
|
#ifdef HAVE_GCC_ATOMICS
|
||||||
|
return __atomic_load_n(a, __ATOMIC_SEQ_CST);
|
||||||
|
#else
|
||||||
void *value;
|
void *value;
|
||||||
do {
|
do {
|
||||||
value = *a;
|
value = *a;
|
||||||
} while (!SDL_AtomicCASPtr(a, value, value));
|
} while (!SDL_AtomicCASPtr(a, value, value));
|
||||||
return value;
|
return value;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Loading…
Reference in New Issue
Block a user