mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Changed how synchronization functions are detected
This commit is contained in:
parent
74d7ba276e
commit
bf9ecc7c5f
@ -99,20 +99,20 @@ find_package( OpenGL )
|
||||
# Allow use of non-threadsafe reference counter in cvf::Object on systems with no atomics support
|
||||
if (CMAKE_COMPILER_IS_GNUCC)
|
||||
|
||||
if (NOT DEFINED HAVE_GCC_ATOMICS)
|
||||
if (NOT DEFINED HAVE_GCC_SYNC_FUNCTIONS)
|
||||
check_c_source_compiles("int main(int argc, char **argv) {
|
||||
int a;
|
||||
__sync_add_and_fetch(&a, 1);
|
||||
__sync_fetch_and_add(&a, 1);
|
||||
__sync_sub_and_fetch(&a, 1);
|
||||
__sync_fetch_and_sub(&a, 1); }" HAVE_GCC_ATOMICS)
|
||||
__sync_fetch_and_sub(&a, 1); }" HAVE_GCC_SYNC_FUNCTIONS)
|
||||
endif()
|
||||
|
||||
if (HAVE_GCC_ATOMICS)
|
||||
message("Atomics supported")
|
||||
if (HAVE_GCC_SYNC_FUNCTIONS)
|
||||
message("GCC synchronization functions detected")
|
||||
else()
|
||||
message("Atomics not supported")
|
||||
add_definitions(-DCVF_WORKAROUND_TO_COMPILE_ON_SYSTEMS_WITHOUT_ATOMICS)
|
||||
message("GCC synchronization functions NOT detected, fallback to non threadsafe reference counting")
|
||||
add_definitions(-DCVF_USE_NON_THREADSAFE_REFERENCE_COUNT)
|
||||
endif()
|
||||
|
||||
endif()
|
||||
|
@ -141,7 +141,7 @@ int AtomicCounter::operator -- (int) // postfix
|
||||
}
|
||||
|
||||
|
||||
#elif defined(CVF_HAVE_GCC_ATOMICS)
|
||||
#elif defined(CVF_GCC_DEFINED)
|
||||
|
||||
|
||||
AtomicCounter::AtomicCounter(int initialValue)
|
||||
|
@ -45,13 +45,8 @@
|
||||
#include <libkern/OSAtomic.h>
|
||||
#define CVF_ATOMIC_COUNTER_CLASS_EXISTS
|
||||
#elif defined __GNUC__
|
||||
#if (CVF_GCC_VER >= 40200) && (defined(__x86_64__) || defined(__i386__))
|
||||
#define CVF_HAVE_GCC_ATOMICS
|
||||
#define CVF_GCC_DEFINED
|
||||
#define CVF_ATOMIC_COUNTER_CLASS_EXISTS
|
||||
#elif (CVF_GCC_VER >= 40300)
|
||||
#define CVF_HAVE_GCC_ATOMICS
|
||||
#define CVF_ATOMIC_COUNTER_CLASS_EXISTS
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(CVF_ATOMIC_COUNTER_CLASS_EXISTS)
|
||||
|
@ -43,12 +43,8 @@
|
||||
|
||||
#include "cvfAtomicCounter.h"
|
||||
|
||||
#if defined(CVF_ATOMIC_COUNTER_CLASS_EXISTS) && defined(CVF_WORKAROUND_TO_COMPILE_ON_SYSTEMS_WITHOUT_ATOMICS)
|
||||
#error Two mutually exclusive defines detected : CVF_ATOMIC_COUNTER_CLASS_EXISTS && CVF_WORKAROUND_TO_COMPILE_ON_SYSTEMS_WITHOUT_ATOMICS
|
||||
#endif
|
||||
|
||||
#if !defined(CVF_ATOMIC_COUNTER_CLASS_EXISTS) && !defined(CVF_WORKAROUND_TO_COMPILE_ON_SYSTEMS_WITHOUT_ATOMICS)
|
||||
#error No support for atomics. Define CVF_WORKAROUND_TO_COMPILE_ON_SYSTEMS_WITHOUT_ATOMICS to be able to compile
|
||||
#if !defined(CVF_ATOMIC_COUNTER_CLASS_EXISTS) && !defined(CVF_USE_NON_THREADSAFE_REFERENCE_COUNT)
|
||||
#error No support for atomics. Define CVF_USE_NON_THREADSAFE_REFERENCE_COUNT to be able to compile
|
||||
#endif
|
||||
|
||||
namespace cvf {
|
||||
@ -75,10 +71,12 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
#if defined(CVF_ATOMIC_COUNTER_CLASS_EXISTS)
|
||||
mutable AtomicCounter m_refCount;
|
||||
#elif defined(CVF_WORKAROUND_TO_COMPILE_ON_SYSTEMS_WITHOUT_ATOMICS)
|
||||
#if defined(CVF_USE_NON_THREADSAFE_REFERENCE_COUNT)
|
||||
mutable int m_refCount;
|
||||
#elif defined(CVF_ATOMIC_COUNTER_CLASS_EXISTS)
|
||||
mutable AtomicCounter m_refCount;
|
||||
#else
|
||||
#error No support for atomics. Define CVF_USE_NON_THREADSAFE_REFERENCE_COUNT to be able to compile
|
||||
#endif
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user