From: Ivan Maidanski Date: Tue, 20 Nov 2018 20:44:08 +0000 (+0300) Subject: Do not use spin locks if AO test-and-set is emulated (pthreads) X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=70283bbb4590a386ab11201feb578ed50166f030;p=gc Do not use spin locks if AO test-and-set is emulated (pthreads) * include/private/gc_locks.h [BASE_ATOMIC_OPS_EMULATED && GC_PTHREADS] (USE_PTHREAD_LOCKS): Define. * include/private/gc_locks.h [BASE_ATOMIC_OPS_EMULATED && GC_PTHREADS] (USE_SPIN_LOCK): Undefine. * pthread_support.c [(USE_SPIN_LOCK || !NO_PTHREAD_TRYLOCK) && AO_CLEAR] (GC_pause): Do not use AO_compiler_barrier() if BASE_ATOMIC_OPS_EMULATED. * pthread_support.c [AO_HAVE_char_load] (is_collecting): Do not use AO_char_load() if BASE_ATOMIC_OPS_EMULATED. --- diff --git a/include/private/gc_locks.h b/include/private/gc_locks.h index f6e45d59..152ad9d3 100644 --- a/include/private/gc_locks.h +++ b/include/private/gc_locks.h @@ -54,7 +54,8 @@ # if (!defined(AO_HAVE_test_and_set_acquire) || defined(GC_RTEMS_PTHREADS) \ || defined(SN_TARGET_ORBIS) || defined(SN_TARGET_PS3) \ - || defined(GC_WIN32_THREADS) || defined(LINT2)) && defined(GC_PTHREADS) + || defined(GC_WIN32_THREADS) || defined(BASE_ATOMIC_OPS_EMULATED) \ + || defined(LINT2)) && defined(GC_PTHREADS) # define USE_PTHREAD_LOCKS # undef USE_SPIN_LOCK # endif diff --git a/pthread_support.c b/pthread_support.c index 4105077f..61e0a10e 100644 --- a/pthread_support.c +++ b/pthread_support.c @@ -1941,7 +1941,7 @@ STATIC void GC_pause(void) for (i = 0; i < GC_PAUSE_SPIN_CYCLES; ++i) { /* Something that's unlikely to be optimized away. */ -# ifdef AO_CLEAR +# if defined(AO_CLEAR) && !defined(BASE_ATOMIC_OPS_EMULATED) AO_compiler_barrier(); # else GC_noop1(i); @@ -2023,7 +2023,7 @@ STATIC void GC_generic_lock(pthread_mutex_t * lock) #endif /* !USE_SPIN_LOCK || ... */ -#ifdef AO_HAVE_char_load +#if defined(AO_HAVE_char_load) && !defined(BASE_ATOMIC_OPS_EMULATED) # define is_collecting() \ ((GC_bool)AO_char_load((unsigned char *)&GC_collecting)) #else