Do not set GC_lock_holder by call_with_alloc_lock if assertions disabled
authorIvan Maidanski <ivmai@mail.ru>
Mon, 15 Jul 2013 13:18:12 +0000 (17:18 +0400)
committerIvan Maidanski <ivmai@mail.ru>
Mon, 15 Jul 2013 13:18:12 +0000 (17:18 +0400)
* include/private/gc_locks.h (GC_lock_holder): Do not declare unless
GC_ASSERTIONS (the variable is not longer used to prevent recursive
reentry in the system call wrapper).
* misc.c (GC_call_with_alloc_lock): Remove [UN]SET_LOCK_HOLDER
explicit calls since GC_lock_holder is set properly by [UN]LOCK()
(in case of GC_ASSERTIONS).
* pthread_support.c (GC_lock_holder): Do not define unless
GC_ASSERTIONS; adjust comment.
* win32_threads.c (GC_lock_holder): Likewise.

include/private/gc_locks.h
misc.c
pthread_support.c
win32_threads.c

index 4974afa..29e38c9 100644 (file)
@@ -55,9 +55,9 @@
 #    define NOSERVICE
 #    include <windows.h>
 #    define NO_THREAD (DWORD)(-1)
-     GC_EXTERN DWORD GC_lock_holder;
      GC_EXTERN CRITICAL_SECTION GC_allocate_ml;
 #    ifdef GC_ASSERTIONS
+         GC_EXTERN DWORD GC_lock_holder;
 #        define UNCOND_LOCK() \
                 { GC_ASSERT(I_DONT_HOLD_LOCK()); \
                   EnterCriticalSection(&GC_allocate_ml); \
 #    define ENTER_GC() GC_collecting = 1;
 #    define EXIT_GC() GC_collecting = 0;
      GC_INNER void GC_lock(void);
-     GC_EXTERN unsigned long GC_lock_holder;
+#    ifdef GC_ASSERTIONS
+       GC_EXTERN unsigned long GC_lock_holder;
+#    endif
 #  endif /* GC_PTHREADS with linux_threads.c implementation */
    GC_EXTERN GC_bool GC_need_to_lock;
 
diff --git a/misc.c b/misc.c
index f0e4480..366603c 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -1808,14 +1808,9 @@ GC_API void * GC_CALL GC_call_with_alloc_lock(GC_fn_type fn, void *client_data)
 
 #   ifdef THREADS
       LOCK();
-      /* FIXME - This looks wrong!! */
-      SET_LOCK_HOLDER();
 #   endif
     result = (*fn)(client_data);
 #   ifdef THREADS
-#     ifndef GC_ASSERTIONS
-        UNSET_LOCK_HOLDER();
-#     endif /* o.w. UNLOCK() does it implicitly */
       UNLOCK();
 #   endif
     return(result);
index e851907..994a2ed 100644 (file)
 #if !defined(USE_SPIN_LOCK)
   GC_INNER pthread_mutex_t GC_allocate_ml = PTHREAD_MUTEX_INITIALIZER;
 #endif
-GC_INNER unsigned long GC_lock_holder = NO_THREAD;
-                /* Used only for assertions, and to prevent      */
-                /* recursive reentry in the system call wrapper. */
+
+#ifdef GC_ASSERTIONS
+  GC_INNER unsigned long GC_lock_holder = NO_THREAD;
+                /* Used only for assertions.    */
+#endif
 
 #if defined(GC_DGUX386_THREADS)
 # include <sys/dg_sys_info.h>
index 4fd1d92..c16946b 100644 (file)
 /* Allocation lock declarations.        */
 #if !defined(USE_PTHREAD_LOCKS)
   GC_INNER CRITICAL_SECTION GC_allocate_ml;
-  GC_INNER DWORD GC_lock_holder = NO_THREAD;
+# ifdef GC_ASSERTIONS
+    GC_INNER DWORD GC_lock_holder = NO_THREAD;
         /* Thread id for current holder of allocation lock */
+# endif
 #else
   GC_INNER pthread_mutex_t GC_allocate_ml = PTHREAD_MUTEX_INITIALIZER;
-  GC_INNER unsigned long GC_lock_holder = NO_THREAD;
+# ifdef GC_ASSERTIONS
+    GC_INNER unsigned long GC_lock_holder = NO_THREAD;
+# endif
 #endif
 
 #undef CreateThread