From 4c0c2e42923f3e4912d848fd034935650e63fe56 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Tue, 11 Apr 2023 22:10:09 +0300 Subject: Acquire GC lock in GC_is_tmp_root * include/gc/gc_mark.h (GC_is_tmp_root): Document function. * include/gc/gc_mark.h (GC_is_tmp_root): Add comment that the function acquires the GC lock. * mark_rts.c [!NO_DEBUGGING] (GC_is_tmp_root): Likewise. * mark_rts.c [!NO_DEBUGGING] (GC_is_tmp_root): Define res local variable; change code to have only single return statement; wrap code into LOCK/UNLOCK. --- mark_rts.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'mark_rts.c') diff --git a/mark_rts.c b/mark_rts.c index 5caff4af..289d7024 100644 --- a/mark_rts.c +++ b/mark_rts.c @@ -469,23 +469,32 @@ STATIC void GC_remove_roots_inner(ptr_t b, ptr_t e) /* For the debugging purpose only. */ /* Workaround for the OS mapping and unmapping behind our back: */ /* Is the address p in one of the temporary static root sections? */ + /* Acquires the GC lock. */ GC_API int GC_CALL GC_is_tmp_root(void *p) { static int last_root_set = MAX_ROOT_SETS; - int i; + int res; + LOCK(); if (last_root_set < n_root_sets && (word)p >= (word)GC_static_roots[last_root_set].r_start - && (word)p < (word)GC_static_roots[last_root_set].r_end) - return GC_static_roots[last_root_set].r_tmp; - for (i = 0; i < n_root_sets; i++) { + && (word)p < (word)GC_static_roots[last_root_set].r_end) { + res = (int)GC_static_roots[last_root_set].r_tmp; + } else { + int i; + + res = 0; + for (i = 0; i < n_root_sets; i++) { if ((word)p >= (word)GC_static_roots[i].r_start && (word)p < (word)GC_static_roots[i].r_end) { - last_root_set = i; - return GC_static_roots[i].r_tmp; + res = (int)GC_static_roots[i].r_tmp; + last_root_set = i; + break; } + } } - return FALSE; + UNLOCK(); + return res; } #endif /* !NO_DEBUGGING */ -- cgit v1.2.1