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:
@@ -99,20 +99,20 @@ find_package( OpenGL )
|
|||||||
# Allow use of non-threadsafe reference counter in cvf::Object on systems with no atomics support
|
# Allow use of non-threadsafe reference counter in cvf::Object on systems with no atomics support
|
||||||
if (CMAKE_COMPILER_IS_GNUCC)
|
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) {
|
check_c_source_compiles("int main(int argc, char **argv) {
|
||||||
int a;
|
int a;
|
||||||
__sync_add_and_fetch(&a, 1);
|
__sync_add_and_fetch(&a, 1);
|
||||||
__sync_fetch_and_add(&a, 1);
|
__sync_fetch_and_add(&a, 1);
|
||||||
__sync_sub_and_fetch(&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()
|
endif()
|
||||||
|
|
||||||
if (HAVE_GCC_ATOMICS)
|
if (HAVE_GCC_SYNC_FUNCTIONS)
|
||||||
message("Atomics supported")
|
message("GCC synchronization functions detected")
|
||||||
else()
|
else()
|
||||||
message("Atomics not supported")
|
message("GCC synchronization functions NOT detected, fallback to non threadsafe reference counting")
|
||||||
add_definitions(-DCVF_WORKAROUND_TO_COMPILE_ON_SYSTEMS_WITHOUT_ATOMICS)
|
add_definitions(-DCVF_USE_NON_THREADSAFE_REFERENCE_COUNT)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
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)
|
AtomicCounter::AtomicCounter(int initialValue)
|
||||||
|
|||||||
@@ -45,13 +45,8 @@
|
|||||||
#include <libkern/OSAtomic.h>
|
#include <libkern/OSAtomic.h>
|
||||||
#define CVF_ATOMIC_COUNTER_CLASS_EXISTS
|
#define CVF_ATOMIC_COUNTER_CLASS_EXISTS
|
||||||
#elif defined __GNUC__
|
#elif defined __GNUC__
|
||||||
#if (CVF_GCC_VER >= 40200) && (defined(__x86_64__) || defined(__i386__))
|
#define CVF_GCC_DEFINED
|
||||||
#define CVF_HAVE_GCC_ATOMICS
|
|
||||||
#define CVF_ATOMIC_COUNTER_CLASS_EXISTS
|
#define CVF_ATOMIC_COUNTER_CLASS_EXISTS
|
||||||
#elif (CVF_GCC_VER >= 40300)
|
|
||||||
#define CVF_HAVE_GCC_ATOMICS
|
|
||||||
#define CVF_ATOMIC_COUNTER_CLASS_EXISTS
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CVF_ATOMIC_COUNTER_CLASS_EXISTS)
|
#if defined(CVF_ATOMIC_COUNTER_CLASS_EXISTS)
|
||||||
|
|||||||
@@ -43,12 +43,8 @@
|
|||||||
|
|
||||||
#include "cvfAtomicCounter.h"
|
#include "cvfAtomicCounter.h"
|
||||||
|
|
||||||
#if defined(CVF_ATOMIC_COUNTER_CLASS_EXISTS) && defined(CVF_WORKAROUND_TO_COMPILE_ON_SYSTEMS_WITHOUT_ATOMICS)
|
#if !defined(CVF_ATOMIC_COUNTER_CLASS_EXISTS) && !defined(CVF_USE_NON_THREADSAFE_REFERENCE_COUNT)
|
||||||
#error Two mutually exclusive defines detected : CVF_ATOMIC_COUNTER_CLASS_EXISTS && CVF_WORKAROUND_TO_COMPILE_ON_SYSTEMS_WITHOUT_ATOMICS
|
#error No support for atomics. Define CVF_USE_NON_THREADSAFE_REFERENCE_COUNT to be able to compile
|
||||||
#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
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace cvf {
|
namespace cvf {
|
||||||
@@ -75,10 +71,12 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
#if defined(CVF_ATOMIC_COUNTER_CLASS_EXISTS)
|
#if defined(CVF_USE_NON_THREADSAFE_REFERENCE_COUNT)
|
||||||
mutable AtomicCounter m_refCount;
|
|
||||||
#elif defined(CVF_WORKAROUND_TO_COMPILE_ON_SYSTEMS_WITHOUT_ATOMICS)
|
|
||||||
mutable int m_refCount;
|
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
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user