Changeset: cb80cba971c3 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=cb80cba971c3 Modified Files: gdk/gdk_atomic.h gdk/gdk_system.c gdk/gdk_system.h gdk/gdk_utils.c Branch: Oct2014 Log Message:
Rationalized choices for locking with pthreads or atomic instructions. Define symbol NO_ATOMIC_INSTRUCTIONS in gdk_atomic.h to not use atomic instructions at all (and hence pthreads locking), or define symbol USE_PTHREAD_LOCKS in gdk_system.h to use pthreads for locking but still atomic instructions where possible. diffs (92 lines): diff --git a/gdk/gdk_atomic.h b/gdk/gdk_atomic.h --- a/gdk/gdk_atomic.h +++ b/gdk/gdk_atomic.h @@ -49,7 +49,10 @@ #ifndef _GDK_ATOMIC_H_ #define _GDK_ATOMIC_H_ -#if defined(HAVE_LIBATOMIC_OPS) && !defined(USE_PTHREAD_LOCKS) +/* define this if you don't want to use atomic instructions */ +/* #define NO_ATOMIC_INSTRUCTIONS */ + +#if defined(HAVE_LIBATOMIC_OPS) && !defined(NO_ATOMIC_INSTRUCTIONS) #include <atomic_ops.h> @@ -71,7 +74,7 @@ #else -#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && !defined(USE_PTHREAD_LOCKS) +#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && !defined(NO_ATOMIC_INSTRUCTIONS) #include <intrin.h> @@ -118,7 +121,7 @@ #define ATOMIC_TAS(var, lck, fcn) _InterlockedCompareExchange(&var, 1, 0) #pragma intrinsic(_InterlockedCompareExchange) -#elif (defined(__GNUC__) || defined(__INTEL_COMPILER)) && !(defined(__sun__) && SIZEOF_SIZE_T == SIZEOF_LNG) && !defined(_MSC_VER) && !defined(USE_PTHREAD_LOCKS) +#elif (defined(__GNUC__) || defined(__INTEL_COMPILER)) && !(defined(__sun__) && SIZEOF_SIZE_T == SIZEOF_LNG) && !defined(_MSC_VER) && !defined(NO_ATOMIC_INSTRUCTIONS) #if SIZEOF_SSIZE_T == SIZEOF_LNG #define ATOMIC_TYPE lng @@ -237,7 +240,8 @@ static inline ATOMIC_TYPE } #define ATOMIC_DEC(var, lck, fcn) __ATOMIC_DEC(&var, &(lck)) -#define ATOMIC_LOCK /* must use locks */ +#define USE_PTHREAD_LOCKS /* must use pthread locks */ +#define ATOMIC_LOCK /* must use locks for atomic access */ #define ATOMIC_INIT(lck, fcn) MT_lock_init(&(lck), fcn) #define ATOMIC_FLAG int diff --git a/gdk/gdk_system.c b/gdk/gdk_system.c --- a/gdk/gdk_system.c +++ b/gdk/gdk_system.c @@ -68,7 +68,7 @@ MT_Lock MT_system_lock MT_LOCK_INITIALIZER("MT_system_lock"); -#if !defined(ATOMIC_LOCK) && !defined(NDEBUG) +#if !defined(USE_PTHREAD_LOCKS) && !defined(NDEBUG) ATOMIC_TYPE volatile GDKlockcnt; ATOMIC_TYPE volatile GDKlockcontentioncnt; ATOMIC_TYPE volatile GDKlocksleepcnt; @@ -401,7 +401,7 @@ MT_kill_thread(MT_Id t) return -1; } -#ifdef ATOMIC_LOCK +#ifdef USE_PTHREAD_LOCKS void pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexattr) diff --git a/gdk/gdk_system.h b/gdk/gdk_system.h --- a/gdk/gdk_system.h +++ b/gdk/gdk_system.h @@ -164,7 +164,11 @@ gdk_export int pthread_mutex_unlock(pthr #include "gdk_atomic.h" -#ifdef ATOMIC_LOCK +/* define this if you want to use pthread (or Windows) locks instead + * of atomic instructions for locking (latching) */ +/* #define USE_PTHREAD_LOCKS */ + +#ifdef USE_PTHREAD_LOCKS typedef pthread_mutex_t MT_Lock; diff --git a/gdk/gdk_utils.c b/gdk/gdk_utils.c --- a/gdk/gdk_utils.c +++ b/gdk/gdk_utils.c @@ -1260,7 +1260,7 @@ GDKexit(int status) #endif GDKlog(GDKLOGOFF); GDKunlockHome(); -#if !defined(ATOMIC_LOCK) && !defined(NDEBUG) +#if !defined(USE_PTHREAD_LOCKS) && !defined(NDEBUG) TEMDEBUG GDKlockstatistics(1); #endif MT_global_exit(status); _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list