Skip to content
Permalink
Browse files

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.
  • Loading branch information
jlegg0 committed Mar 29, 2017
1 parent 266816b commit 1dc9ae5c1e058a7e6b1711ba031bc2ceb95cf6aa
Showing with 8 additions and 0 deletions.
  1. +8 −0 src/atomic/SDL_atomic.c
@@ -211,21 +211,29 @@ SDL_AtomicAdd(SDL_atomic_t *a, int v)
int
SDL_AtomicGet(SDL_atomic_t *a)
{
#ifdef HAVE_GCC_ATOMICS
return __atomic_load_n(&a->value, __ATOMIC_SEQ_CST);
#else
int value;
do {
value = a->value;
} while (!SDL_AtomicCAS(a, value, value));
return value;
#endif
}

void *
SDL_AtomicGetPtr(void **a)
{
#ifdef HAVE_GCC_ATOMICS
return __atomic_load_n(a, __ATOMIC_SEQ_CST);
#else
void *value;
do {
value = *a;
} while (!SDL_AtomicCASPtr(a, value, value));
return value;
#endif
}

void

0 comments on commit 1dc9ae5

Please sign in to comment.