Changeset: 906dededa790 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/906dededa790 Modified Files: cmake/monetdb-defines.cmake common/utils/matomic.h monetdb_config.h.in Branch: default Log Message:
Use a 64 bit unsigned integer for our atomic type. diffs (163 lines): diff --git a/cmake/monetdb-defines.cmake b/cmake/monetdb-defines.cmake --- a/cmake/monetdb-defines.cmake +++ b/cmake/monetdb-defines.cmake @@ -238,7 +238,7 @@ macro(monetdb_configure_sizes) check_type_size(short SIZEOF_SHORT LANGUAGE C) check_type_size(int SIZEOF_INT LANGUAGE C) check_type_size(long SIZEOF_LONG LANGUAGE C) - check_type_size("long int" SIZEOF_LONG_INT LANGUAGE C) + check_type_size("long long" SIZEOF_LONG_LONG LANGUAGE C) check_type_size(double SIZEOF_DOUBLE LANGUAGE C) check_type_size(wchar_t SIZEOF_WCHAR_T LANGUAGE C) cmake_push_check_state() diff --git a/common/utils/matomic.h b/common/utils/matomic.h --- a/common/utils/matomic.h +++ b/common/utils/matomic.h @@ -23,8 +23,7 @@ * ATOMIC_SUB -- subtract a value from a variable, return original value; * ATOMIC_INC -- increment a variable's value, return new value; * ATOMIC_DEC -- decrement a variable's value, return new value; - * These interfaces work on variables of type ATOMIC_TYPE - * (int or int64_t depending on architecture). + * These interfaces work on variables of type ATOMIC_TYPE (uint64_t). * * The compare-and-set operation is based on the C11 standard: if the * atomic variable equals the expected value, the atomic variable is @@ -57,33 +56,21 @@ /* define this if you don't want to use atomic instructions */ /* #define NO_ATOMIC_INSTRUCTIONS */ +/* the atomic type we export is always a 64 bit unsigned integer */ +typedef uint64_t ATOMIC_BASE_TYPE; + /* ignore __STDC_NO_ATOMICS__ if compiling using Intel compiler on * Windows since otherwise we can't compile this at all in C99 mode */ #if defined(HAVE_STDATOMIC_H) && (!defined(__STDC_NO_ATOMICS__) || (defined(__INTEL_COMPILER) && defined(_WINDOWS))) && !defined(NO_ATOMIC_INSTRUCTIONS) #include <stdatomic.h> -#if ATOMIC_LLONG_LOCK_FREE == 2 -typedef volatile atomic_ullong ATOMIC_TYPE; -typedef unsigned long long ATOMIC_BASE_TYPE; -#elif ATOMIC_LONG_LOCK_FREE == 2 -typedef volatile atomic_ulong ATOMIC_TYPE; -typedef unsigned long ATOMIC_BASE_TYPE; -#elif ATOMIC_INT_LOCK_FREE == 2 -typedef volatile atomic_uint ATOMIC_TYPE; -typedef unsigned int ATOMIC_BASE_TYPE; -#elif ATOMIC_LLONG_LOCK_FREE == 1 +#if SIZEOF_LONG_LONG == 8 typedef volatile atomic_ullong ATOMIC_TYPE; -typedef unsigned long long ATOMIC_BASE_TYPE; -#elif ATOMIC_LONG_LOCK_FREE == 1 +#elif SIZEOF_LONG == 8 typedef volatile atomic_ulong ATOMIC_TYPE; -typedef unsigned long ATOMIC_BASE_TYPE; -#elif ATOMIC_INT_LOCK_FREE == 1 -typedef volatile atomic_uint ATOMIC_TYPE; -typedef unsigned int ATOMIC_BASE_TYPE; #else -typedef volatile atomic_ullong ATOMIC_TYPE; -typedef unsigned long long ATOMIC_BASE_TYPE; +#error "we need a 64 bit atomic type" #endif #define ATOMIC_INIT(var, val) atomic_init(var, (ATOMIC_BASE_TYPE) (val)) @@ -138,19 +125,18 @@ typedef volatile atomic_flag ATOMIC_FLAG * documentation. */ -typedef __declspec(align(8)) volatile int64_t ATOMIC_TYPE; -typedef int64_t ATOMIC_BASE_TYPE; - -#if SIZEOF_SIZE_T == 8 +typedef __declspec(align(8)) volatile ATOMIC_BASE_TYPE ATOMIC_TYPE; #define ATOMIC_VAR_INIT(val) (val) #define ATOMIC_INIT(var, val) (*(var) = (val)) -#define ATOMIC_DESTROY(var) ((void) 0) +#define ATOMIC_DESTROY(var) ((void) 0) + +#if SIZEOF_SIZE_T == 8 #ifdef __INTEL_COMPILER -#define ATOMIC_GET(var) _InterlockedExchangeAdd64(var, 0) +#define ATOMIC_GET(var) _InterlockedExchangeAdd64(var, 0) #else -#define ATOMIC_GET(var) (*(var)) +#define ATOMIC_GET(var) (*(var)) /* should we use _InterlockedExchangeAdd64(var, 0) instead? */ #endif #define ATOMIC_SET(var, val) _InterlockedExchange64(var, (ATOMIC_BASE_TYPE) (val)) @@ -167,7 +153,7 @@ ATOMIC_CAS(ATOMIC_TYPE *var, ATOMIC_BASE } #define ATOMIC_CAS(var, exp, des) ATOMIC_CAS(var, exp, (ATOMIC_BASE_TYPE) (des)) #define ATOMIC_ADD(var, val) _InterlockedExchangeAdd64(var, (ATOMIC_BASE_TYPE) (val)) -#define ATOMIC_SUB(var, val) _InterlockedExchangeAdd64(var, -(ATOMIC_BASE_TYPE) (val)) +#define ATOMIC_SUB(var, val) _InterlockedExchangeAdd64(var, -(val)) #define ATOMIC_INC(var) _InterlockedIncrement64(var) #define ATOMIC_DEC(var) _InterlockedDecrement64(var) #define ATOMIC_OR(var, val) _InterlockedOr64(var, (ATOMIC_BASE_TYPE) (val)) @@ -175,16 +161,12 @@ ATOMIC_CAS(ATOMIC_TYPE *var, ATOMIC_BASE #else -#define ATOMIC_VAR_INIT(val) (val) -#define ATOMIC_INIT(var, val) (*(var) = (val)) -#define ATOMIC_DESTROY(var) ((void) 0) - #ifdef DECLSPEC_NOINITALL #define ATOMIC_GET(var) _InlineInterlockedExchangeAdd64(var, 0) #define ATOMIC_SET(var, val) _InlineInterlockedExchange64(var, (ATOMIC_BASE_TYPE) (val)) #define ATOMIC_XCG(var, val) _InlineInterlockedExchange64(var, (ATOMIC_BASE_TYPE) (val)) #define ATOMIC_ADD(var, val) _InlineInterlockedExchangeAdd64(var, (ATOMIC_BASE_TYPE) (val)) -#define ATOMIC_SUB(var, val) _InlineInterlockedExchangeAdd64(var, -(ATOMIC_BASE_TYPE) (val)) +#define ATOMIC_SUB(var, val) _InlineInterlockedExchangeAdd64(var, -(val)) #define ATOMIC_INC(var) _InlineInterlockedIncrement64(var) #define ATOMIC_DEC(var) _InlineInterlockedDecrement64(var) #define ATOMIC_OR(var, val) _InlineInterlockedOr64(var, (ATOMIC_BASE_TYPE) (val)) @@ -194,7 +176,7 @@ ATOMIC_CAS(ATOMIC_TYPE *var, ATOMIC_BASE #define ATOMIC_SET(var, val) _InterlockedExchange64(var, (ATOMIC_BASE_TYPE) (val)) #define ATOMIC_XCG(var, val) _InterlockedExchange64(var, (ATOMIC_BASE_TYPE) (val)) #define ATOMIC_ADD(var, val) _InterlockedExchangeAdd64(var, (ATOMIC_BASE_TYPE) (val)) -#define ATOMIC_SUB(var, val) _InterlockedExchangeAdd64(var, -(ATOMIC_BASE_TYPE) (val)) +#define ATOMIC_SUB(var, val) _InterlockedExchangeAdd64(var, -(val)) #define ATOMIC_INC(var) _InterlockedIncrement64(var) #define ATOMIC_DEC(var) _InterlockedDecrement64(var) #define ATOMIC_OR(var, val) _InterlockedOr64(var, (ATOMIC_BASE_TYPE) (val)) @@ -245,13 +227,8 @@ typedef volatile int ATOMIC_FLAG; /* the new way of doing this according to GCC (the old way, using * __sync_* primitives is not supported) */ -#if SIZEOF_SIZE_T == 8 -typedef int64_t ATOMIC_BASE_TYPE; -typedef volatile int64_t ATOMIC_TYPE; -#else -typedef int ATOMIC_BASE_TYPE; -typedef volatile int ATOMIC_TYPE; -#endif +typedef volatile ATOMIC_BASE_TYPE ATOMIC_TYPE; + #define ATOMIC_VAR_INIT(val) (val) #define ATOMIC_INIT(var, val) (*(var) = (val)) #define ATOMIC_DESTROY(var) ((void) 0) @@ -287,7 +264,6 @@ typedef volatile char ATOMIC_FLAG; #include <pthread.h> /* required for pthread_mutex_t */ -typedef size_t ATOMIC_BASE_TYPE; typedef struct { ATOMIC_BASE_TYPE val; pthread_mutex_t lck; diff --git a/monetdb_config.h.in b/monetdb_config.h.in --- a/monetdb_config.h.in +++ b/monetdb_config.h.in @@ -290,7 +290,7 @@ #cmakedefine SIZEOF_SHORT @SIZEOF_SHORT@ #cmakedefine SIZEOF_INT @SIZEOF_INT@ #cmakedefine SIZEOF_LONG @SIZEOF_LONG@ -#cmakedefine SIZEOF_LONG_INT @SIZEOF_LONG_INT@ +#cmakedefine SIZEOF_LONG_LONG @SIZEOF_LONG_LONG@ #cmakedefine SIZEOF_DOUBLE @SIZEOF_DOUBLE@ #cmakedefine SIZEOF_WCHAR_T @SIZEOF_WCHAR_T@ #define HAVE_LONG_LONG 1 /* for ODBC include files */ _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list