From ca85a663a1f57f427ad815cb0e9aa54c259ec6c9 Mon Sep 17 00:00:00 2001 From: Pavel Krajcevski Date: Wed, 6 Mar 2013 17:16:36 -0500 Subject: [PATCH] Add detection for atomics Atomic operations are both supported by the platform and the compiler. If we want to provide a threadsafe implementation of our compression function, we need to make sure that the proper settings are available. --- BPTCEncoder/CMakeLists.txt | 30 ++++++++++++++++++++++++++++++ BPTCEncoder/config/BC7Config.h.in | 4 ++++ 2 files changed, 34 insertions(+) diff --git a/BPTCEncoder/CMakeLists.txt b/BPTCEncoder/CMakeLists.txt index 239801d..bae84c0 100644 --- a/BPTCEncoder/CMakeLists.txt +++ b/BPTCEncoder/CMakeLists.txt @@ -144,6 +144,36 @@ IF( NOT HAS_INLINE_ASSEMBLY AND NOT HAS_INLINE_ASSEMBLY_WITH_FLAGS ) SET( NO_INLINE_ASSEMBLY true ) ENDIF() +# Check to see whether or not our compiler supports atomic operations +IF( CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX ) + + CHECK_CXX_SOURCE_RUNS(" + int main() { + int x = 0; + __sync_fetch_and_add(&x, 1); + return !x; + }" + HAS_GCC_ATOMICS + ) + +ELSEIF( MSVC ) + + CHECK_CXX_SOURCE_RUNS(" + #include + int main() { + int *x = _aligned_malloc(sizeof(int), 32); + x = InterlockedIncrement(&x); + free(x); + return !x; + }" + HAS_MSVC_ATOMICS + ) + +ENDIF() +IF( HAS_MSVC_ATOMICS OR HAS_GCC_ATOMICS ) + SET(HAS_ATOMICS true) +ENDIF() + CONFIGURE_FILE( "config/BC7Config.h.in" "include/BC7Config.h" diff --git a/BPTCEncoder/config/BC7Config.h.in b/BPTCEncoder/config/BC7Config.h.in index b5bbcb3..0bdce7b 100644 --- a/BPTCEncoder/config/BC7Config.h.in +++ b/BPTCEncoder/config/BC7Config.h.in @@ -48,3 +48,7 @@ #cmakedefine NO_INLINE_ASSEMBLY #cmakedefine HAS_SSE_POPCNT #cmakedefine HAS_SSE_41 + +#cmakedefine HAS_ATOMICS +#cmakedefine HAS_GCC_ATOMICS +#cmakedefine HAS_MSVC_ATOMICS