]> granicus.if.org Git - gc/commitdiff
New API function (GC_is_init_called) to check if BDWGC is initialized
authorIvan Maidanski <ivmai@mail.ru>
Mon, 16 Oct 2017 07:25:57 +0000 (10:25 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Wed, 25 Oct 2017 10:03:39 +0000 (13:03 +0300)
(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.

include/gc.h
misc.c
tests/test.c

index 8597616b25eaee4c707ec0f81ac4a7887907c84f..472e478433dbce8bee98b81adad211121e2abb17 100644 (file)
@@ -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 00a294789e478eb5e5e7355673887f6bc8cce799..9cbe75066d2adaebd3e573c7cd4746e19ade3582 100644 (file)
--- 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
index 196b8963458028f00e3c50e63c65419c6ee2dda4..c60c7c93ae573a75127598fe2601e82571238bd2 100644 (file)
@@ -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  */