From: Ivan Maidanski Date: Fri, 8 Jun 2018 20:41:22 +0000 (+0300) Subject: Fix 'collecting from unknown thread' abort in leak-finding mode X-Git-Tag: v8.0.0~131 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8e6460052c70fa1fc7be62947f87a596009f744d;p=platform%2Fupstream%2Flibgc.git Fix 'collecting from unknown thread' abort in leak-finding mode * include/private/gc_priv.h [GC_PTHREADS && !GC_WIN32_THREADS] (GC_in_thread_creation): Move variable declaration from pthread_support.h. * misc.c [!DONT_USE_ATEXIT && GC_PTHREADS && !GC_WIN32_THREADS] (GC_exit_check): Set GC_in_thread_creation to TRUE before GC_gcollect call. --- diff --git a/include/private/gc_priv.h b/include/private/gc_priv.h index 953a31f..40bc0d3 100644 --- a/include/private/gc_priv.h +++ b/include/private/gc_priv.h @@ -1951,6 +1951,13 @@ GC_INNER GC_bool GC_try_to_collect_inner(GC_stop_func f); #define GC_gcollect_inner() \ (void)GC_try_to_collect_inner(GC_never_stop_func) +#if defined(GC_PTHREADS) && !defined(GC_WIN32_THREADS) + GC_EXTERN GC_bool GC_in_thread_creation; + /* We may currently be in thread creation or destruction. */ + /* Only set to TRUE while allocation lock is held. */ + /* When set, it is OK to run GC from unknown thread. */ +#endif + GC_EXTERN GC_bool GC_is_initialized; /* GC_init() has been run. */ GC_INNER void GC_collect_a_little_inner(int n); diff --git a/include/private/pthread_support.h b/include/private/pthread_support.h index ae5c2e9..2dc1541 100644 --- a/include/private/pthread_support.h +++ b/include/private/pthread_support.h @@ -158,11 +158,6 @@ GC_EXTERN GC_bool GC_thr_initialized; GC_INNER GC_thread GC_lookup_thread(pthread_t id); -GC_EXTERN GC_bool GC_in_thread_creation; - /* We may currently be in thread creation or destruction. */ - /* Only set to TRUE while allocation lock is held. */ - /* When set, it is OK to run GC from unknown thread. */ - #ifdef NACL GC_EXTERN __thread GC_thread GC_nacl_gc_thread_self; GC_INNER void GC_nacl_initialize_gc_thread(void); diff --git a/misc.c b/misc.c index c91c788..2ae2606 100644 --- a/misc.c +++ b/misc.c @@ -760,7 +760,13 @@ GC_API int GC_CALL GC_is_init_called(void) STATIC void GC_exit_check(void) { if (GC_find_leak && !skip_gc_atexit) { - GC_gcollect(); +# if defined(GC_PTHREADS) && !defined(GC_WIN32_THREADS) + GC_in_thread_creation = TRUE; /* OK to collect from unknown thread. */ + GC_gcollect(); + GC_in_thread_creation = FALSE; +# else + GC_gcollect(); +# endif } } #endif