summaryrefslogtreecommitdiff
path: root/finalize.c
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2017-10-20 00:25:52 +0300
committerIvan Maidanski <ivmai@mail.ru>2017-10-20 00:25:52 +0300
commitb850e1c9bb460d54d7a5e1131fe78f3474700251 (patch)
treef27444823a95c261142249fca0a4ba7f57dbfd68 /finalize.c
parent243ab168e4237aa4e48e74949d1995282616be7b (diff)
downloadbdwgc-b850e1c9bb460d54d7a5e1131fe78f3474700251.tar.gz
Workaround Thread Sanitizer (TSan) false positive warnings (partially)
This patch covers only data race false positive warnings reported in async_set_pht_entry_from_index, GC_clear_stack, GC_invoke_finalizers, GC_lock, GC_noop1, GC_notify_or_invoke_finalizers, GC_pthread_create, GC_suspend_handler_inner, I_DONT_HOLD_LOCK. * finalize.c (GC_should_invoke_finalizers): Add GC_ATTR_NO_SANITIZE_THREAD. * mark.c (GC_noop1): Likewise. * os_dep.c [MPROTECT_VDB && THREADS && AO_HAVE_test_and_set_acquire] (async_set_pht_entry_from_index): Likewise. * finalize.c (GC_invoke_finalizers, GC_notify_or_invoke_finalizers): Call GC_should_invoke_finalizers() instead of GC_fnlz_roots.finalize_now!=NULL. * include/private/gc_locks.h [(GC_WIN32_THREADS && !USE_PTHREAD_LOCKS || GC_PTHREADS) && GC_ASSERTIONS && THREAD_SANITIZER] (I_DONT_HOLD_LOCK): Define to TRUE; add comment. * include/private/gc_locks.h [!GC_ALWAYS_MULTITHREADED && THREAD_SANITIZER] (set_need_to_lock): Do not set GC_need_to_lock if already set; add comment. * include/private/gc_priv.h [!GC_ATTR_NO_SANITIZE_THREAD] (GC_ATTR_NO_SANITIZE_THREAD): New macro. * include/private/gcconfig.h [__has_feature && __has_feature(thread_sanitizer)] (THREAD_SANITIZER): Define. * misc.c [THREADS] (next_random_no): New static function (with GC_ATTR_NO_SANITIZE_THREAD). * pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL] (update_last_stop_count): Likewise. * pthread_support.c [THREAD_SANITIZER && (USE_SPIN_LOCK || !NO_PTHREAD_TRYLOCK)] (is_collecting): Likewise. * pthread_support.c [USE_SPIN_LOCK] (set_last_spins_and_high_spin_max, reset_spin_max): Likewise. * misc.c [THREADS] (GC_clear_stack): Remove random_no static variable; use next_random_no() instead of ++random_no%13. * pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL] (GC_suspend_handler_inner): Call update_last_stop_count() instead of me->stop_info.last_stop_count=my_stop_count. * pthread_support.c [USE_SPIN_LOCK || !NO_PTHREAD_TRYLOCK] (SPIN_MAX): Define only if not yet. * pthread_support.c [USE_SPIN_LOCK || !NO_PTHREAD_TRYLOCK] (GC_collecting): Initialize to FALSE instead of 0. * pthread_support.c [!(THREAD_SANITIZER && (USE_SPIN_LOCK || !NO_PTHREAD_TRYLOCK))] (is_collecting): Define as a macro. * pthread_support.c [USE_SPIN_LOCK] (low_spin_max, high_spin_max, spin_max, last_spins): Move definition out of GC_lock(). * pthread_support.c (GC_lock): Use is_collecting(), set_last_spins_and_high_spin_max() and reset_spin_max().
Diffstat (limited to 'finalize.c')
-rw-r--r--finalize.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/finalize.c b/finalize.c
index 88ce2ebc..0c39b54d 100644
--- a/finalize.c
+++ b/finalize.c
@@ -1183,6 +1183,7 @@ GC_INNER void GC_finalize(void)
/* finalizers can only be called from some kind of "safe state" and */
/* getting into that safe state is expensive.) */
GC_API int GC_CALL GC_should_invoke_finalizers(void)
+ GC_ATTR_NO_SANITIZE_THREAD
{
return GC_fnlz_roots.finalize_now != NULL;
}
@@ -1195,7 +1196,7 @@ GC_API int GC_CALL GC_invoke_finalizers(void)
word bytes_freed_before = 0; /* initialized to prevent warning. */
DCL_LOCK_STATE;
- while (GC_fnlz_roots.finalize_now != NULL) {
+ while (GC_should_invoke_finalizers()) {
struct finalizable_object * curr_fo;
# ifdef THREADS
@@ -1244,7 +1245,8 @@ GC_INNER void GC_notify_or_invoke_finalizers(void)
# if defined(THREADS) && !defined(KEEP_BACK_PTRS) \
&& !defined(MAKE_BACK_GRAPH)
/* Quick check (while unlocked) for an empty finalization queue. */
- if (NULL == GC_fnlz_roots.finalize_now) return;
+ if (!GC_should_invoke_finalizers())
+ return;
# endif
LOCK();