]> 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>
Tue, 17 Jul 2018 11:39:42 +0000 (14:39 +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 8eedc7720def9d5570cd8c66441846fc6acdacda..df4eb5ed6144b5a467b06e3a8fe0a0b9b81ad430 100644 (file)
@@ -396,6 +396,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 ea629b7778c11258daf58fb0adf91f2996225247..820e0f91052ceee92405066422680db64c3af00d 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -736,6 +736,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 d730d6ecd9c5f6d3422399d1223886bfd34612bb..fd791160ba69f1436908bcd04aedf9f7d6edb4df 100644 (file)
@@ -1456,6 +1456,10 @@ void check_heap_stats(void)
 #     endif
 #   endif
 
+    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  */