From: Ivan Maidanski Date: Mon, 16 Oct 2017 07:25:57 +0000 (+0300) Subject: New API function (GC_is_init_called) to check if BDWGC is initialized X-Git-Tag: v7.6.2~40 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=98fce1f80ba0c5f51a74ef4298db5a5bf7837107;p=gc New API function (GC_is_init_called) to check if BDWGC is initialized (Cherry-pick commit 58c5c05 from 'master' branch.) Issue #186 (bdwgc). * include/gc.h (GC_is_init_called): New API function declaration. * misc.c (GC_is_init_called): New API function definition. * tests/test.c (check_heap_stats): Add a test that GC is initialized. --- diff --git a/include/gc.h b/include/gc.h index 8597616b..472e4784 100644 --- a/include/gc.h +++ b/include/gc.h @@ -440,6 +440,10 @@ GC_API void GC_CALL GC_atfork_child(void); /* from the main program instead. */ GC_API void GC_CALL GC_init(void); +/* Returns non-zero (TRUE) if and only if the collector is initialized */ +/* (or, at least, the initialization is in progress). */ +GC_API int GC_CALL GC_is_init_called(void); + /* General purpose allocation routines, with roughly malloc calling */ /* conv. The atomic versions promise that no relevant pointers are */ /* contained in the object. The non-atomic versions guarantee that the */ diff --git a/misc.c b/misc.c index 00a29478..9cbe7506 100644 --- a/misc.c +++ b/misc.c @@ -745,6 +745,11 @@ GC_API void GC_CALL GC_get_heap_usage_safe(GC_word *pheap_size, GC_INNER GC_bool GC_is_initialized = FALSE; +GC_API int GC_CALL GC_is_init_called(void) +{ + return GC_is_initialized; +} + #if (defined(MSWIN32) || defined(MSWINCE)) && defined(THREADS) GC_INNER CRITICAL_SECTION GC_write_cs; #endif diff --git a/tests/test.c b/tests/test.c index 196b8963..c60c7c93 100644 --- a/tests/test.c +++ b/tests/test.c @@ -1576,6 +1576,10 @@ void check_heap_stats(void) # endif unsigned obj_count = 0; + if (!GC_is_init_called()) { + GC_printf("GC should be initialized!\n"); + FAIL; + } # ifdef VERY_SMALL_CONFIG /* The upper bounds are a guess, which has been empirically */ /* adjusted. On low end uniprocessors with incremental GC */