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.
This commit is contained in:
Pavel Krajcevski 2013-03-06 17:16:36 -05:00
parent 771b91b795
commit ca85a663a1
2 changed files with 34 additions and 0 deletions

View file

@ -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 <Windows.h>
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"

View file

@ -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