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: v8.0.0~549 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=58c5c05;p=gc New API function (GC_is_init_called) to check if BDWGC is initialized 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 9c1406fc..a92b4115 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); + /* Perform the collector shutdown. (E.g. dispose critical sections on */ /* Win32 target.) A duplicate invocation is a no-op. GC_INIT should */ /* not be called after the shutdown. See also GC_win32_free_heap(). */ diff --git a/misc.c b/misc.c index e4607f6d..399613cf 100644 --- a/misc.c +++ b/misc.c @@ -748,6 +748,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 0489a6bb..451bce3d 100644 --- a/tests/test.c +++ b/tests/test.c @@ -1554,6 +1554,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 */