Do not use asm in GC_pause
authorIvan Maidanski <ivmai@mail.ru>
Mon, 31 Jul 2017 07:57:14 +0000 (10:57 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Mon, 31 Jul 2017 07:57:14 +0000 (10:57 +0300)
* pthread_support.c [GC_PTHREADS && !GC_WIN32_THREADS
&& (USE_SPIN_LOCK || !NO_PTHREAD_TRYLOCK)] (GC_PAUSE_SPIN_CYCLES): New
macro.
* pthread_support.c [GC_PTHREADS && !GC_WIN32_THREADS
&& (USE_SPIN_LOCK || !NO_PTHREAD_TRYLOCK)] (GC_pause): Replace "10"
with GC_PAUSE_SPIN_CYCLES; remove "dummy" local variable; use
AO_compiler_barrier() instead of __asm__("") and GC_noop1(++dummy).

pthread_support.c

index ed00ff9..6f80a41 100644 (file)
@@ -1842,20 +1842,14 @@ GC_API int WRAP_FUNC(pthread_create)(pthread_t *new_thread,
 #if defined(USE_SPIN_LOCK) || !defined(NO_PTHREAD_TRYLOCK)
 /* Spend a few cycles in a way that can't introduce contention with     */
 /* other threads.                                                       */
+#define GC_PAUSE_SPIN_CYCLES 10
 STATIC void GC_pause(void)
 {
     int i;
-#   if !defined(__GNUC__) || defined(__INTEL_COMPILER)
-      volatile word dummy = 0;
-#   endif
 
-    for (i = 0; i < 10; ++i) {
-#     if defined(__GNUC__) && !defined(__INTEL_COMPILER)
-        __asm__ __volatile__ (" " : : : "memory");
-#     else
+    for (i = 0; i < GC_PAUSE_SPIN_CYCLES; ++i) {
         /* Something that's unlikely to be optimized away. */
-        GC_noop1(++dummy);
-#     endif
+        AO_compiler_barrier();
     }
 }
 #endif