atomic: Fix missing full memory barrier on GCC/Clang

__sync_lock_test_and_set() is designed for creating locks, not as
a general atomic exchange function. As a result, it only provides
an acquire memory barrier and isn't guaranteed to actually store
the provided value (though it does on architectures we care about).

__atomic_exchange_n() is supported on GCC/Clang for the last ~10
years, so let's use that instead if available. We will keep the
__sync_lock_test_and_set() fallback around for ancient platforms,
but add a full memory barrier to match the documented behavior.
2 files changed
tree: 630a818cdfb38ea1dbc700949476225d48cd9d3a
  1. .github/
  2. acinclude/
  3. android-project/
  4. android-project-ant/
  5. build-scripts/
  6. cmake/
  7. docs/
  8. include/
  9. mingw/
  10. src/
  11. test/
  12. VisualC/
  13. VisualC-GDK/
  14. VisualC-WinRT/
  15. visualtest/
  16. wayland-protocols/
  17. Xcode/
  18. Xcode-iOS/
  19. .clang-format
  20. .editorconfig
  21. .gitignore
  22. .wikiheaders-options
  23. AGENTS.md
  24. Android.mk
  25. autogen.sh
  26. BUGS.txt
  27. CLAUDE.md
  28. cmake_uninstall.cmake.in
  29. CMakeLists.txt
  30. configure
  31. configure.ac
  32. CREDITS.txt
  33. INSTALL.txt
  34. LICENSE.txt
  35. Makefile.in
  36. Makefile.minimal
  37. Makefile.os2
  38. Makefile.pandora
  39. Makefile.w32
  40. README-SDL.txt
  41. README.md
  42. sdl2-config-version.cmake.in
  43. sdl2-config.cmake.in
  44. sdl2-config.in
  45. sdl2.m4
  46. sdl2.pc.in
  47. SDL2.spec.in
  48. SDL2Config.cmake.in
  49. TODO.txt
  50. WhatsNew.txt
README.md

Simple DirectMedia Layer (SDL) Version 2.0

https://www.libsdl.org/

Simple DirectMedia Layer is a cross-platform development library designed to provide low level access to audio, keyboard, mouse, joystick, and graphics hardware via OpenGL and Direct3D. It is used by video playback software, emulators, and popular games including Valve's award winning catalog and many Humble Bundle games.

More extensive documentation is available in the docs directory, starting with README.md

Enjoy!

Sam Lantinga (slouken@libsdl.org)