]> granicus.if.org Git - gc/commitdiff
New API function (GC_is_incremental_mode)
authorIvan Maidanski <ivmai@mail.ru>
Fri, 21 Jul 2017 18:42:18 +0000 (21:42 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Fri, 21 Jul 2017 18:42:18 +0000 (21:42 +0300)
* alloc.c (GC_is_incremental_mode): New public function definition.
* include/gc.h (GC_full_freq): Update comment.
* include/gc.h (GC_is_incremental_mode): New public function
declaration.
* tests/test.c [!GC_WIN32_THREADS && !GC_PTHREADS] (main): Print
"Switched to incremental mode" and friend messages only if
GC_is_incremental_mode().
* tests/test.c [!GC_PTHREADS] (main): Likewise.

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

diff --git a/alloc.c b/alloc.c
index 885d651742dd599f9cdb14d7ff03454c91448dbd..0f18301e880cf3d5e0b784360c7db575f07c9615 100644 (file)
--- a/alloc.c
+++ b/alloc.c
@@ -67,6 +67,11 @@ word GC_gc_no = 0;
   GC_INNER GC_bool GC_incremental = FALSE; /* By default, stop the world. */
 #endif
 
+GC_API int GC_CALL GC_is_incremental_mode(void)
+{
+  return (int)GC_incremental;
+}
+
 #ifdef THREADS
   int GC_parallel = FALSE;      /* By default, parallel GC is off.      */
 #endif
index ebabfb08b5674498d20af07a38d9fed610269bc6..d383869701f5b9c710d06e07c5d897092691e43b 100644 (file)
@@ -272,7 +272,7 @@ GC_API GC_ATTR_DEPRECATED int GC_use_entire_heap;
 GC_API GC_ATTR_DEPRECATED int GC_full_freq;
                             /* Number of partial collections between    */
                             /* full collections.  Matters only if       */
-                            /* GC_incremental is set.                   */
+                            /* GC_is_incremental_mode().                */
                             /* Full collections are also triggered if   */
                             /* the collector detects a substantial      */
                             /* increase in the number of in-use heap    */
@@ -773,6 +773,10 @@ GC_API void GC_CALL GC_enable(void);
 /* Safe to call before GC_INIT().  Includes a  GC_init() call.          */
 GC_API void GC_CALL GC_enable_incremental(void);
 
+/* Return non-zero (TRUE) if and only if the incremental mode is on.    */
+/* Does not acquire the lock.                                           */
+GC_API int GC_CALL GC_is_incremental_mode(void);
+
 /* Does incremental mode write-protect pages?  Returns zero or  */
 /* more of the following, or'ed together:                       */
 #define GC_PROTECTS_POINTER_HEAP  1 /* May protect non-atomic objects.  */
index ddbdd328a6e27ae74fe262c883b3fbd7bcb47a82..4604ca776d022b0aa962d23864176dee6e76ab66 100644 (file)
@@ -1777,20 +1777,23 @@ void GC_CALLBACK warn_proc(char *msg, GC_word p)
 #   endif
     GC_COND_INIT();
     GC_set_warn_proc(warn_proc);
-#   if (defined(MPROTECT_VDB) || defined(PROC_VDB) || defined(GWW_VDB)) \
-          && !defined(MAKE_BACK_GRAPH) && !defined(NO_INCREMENTAL)
-      GC_enable_incremental();
-      GC_printf("Switched to incremental mode\n");
-#     ifdef PROC_VDB
-        GC_printf("Reading dirty bits from /proc\n");
-#     elif defined(GWW_VDB)
-        GC_printf("Using GetWriteWatch-based implementation\n");
-#       ifdef MPROTECT_VDB
-          GC_printf("Or emulating dirty bits with mprotect/signals\n");
-#       endif
-#     else /* MPROTECT_VDB && !GWW_VDB */
-        GC_printf("Emulating dirty bits with mprotect/signals\n");
+#   if defined(MPROTECT_VDB) || defined(PROC_VDB) || defined(GWW_VDB)
+#     if !defined(MAKE_BACK_GRAPH) && !defined(NO_INCREMENTAL)
+        GC_enable_incremental();
 #     endif
+      if (GC_is_incremental_mode()) {
+        GC_printf("Switched to incremental mode\n");
+#       ifdef PROC_VDB
+          GC_printf("Reading dirty bits from /proc\n");
+#       elif defined(GWW_VDB)
+          GC_printf("Using GetWriteWatch-based implementation\n");
+#         ifdef MPROTECT_VDB
+            GC_printf("Or emulating dirty bits with mprotect/signals\n");
+#         endif
+#       else /* MPROTECT_VDB && !GWW_VDB */
+          GC_printf("Emulating dirty bits with mprotect/signals\n");
+#       endif
+      }
 #   endif
     run_one_test();
     check_heap_stats();
@@ -2205,12 +2208,15 @@ int main(void)
         }
 #   endif
     n_tests = 0;
-#   if defined(MPROTECT_VDB) && !defined(REDIRECT_MALLOC) \
-            && !defined(MAKE_BACK_GRAPH) && !defined(USE_PROC_FOR_LIBRARIES) \
-            && !defined(NO_INCREMENTAL)
+#   if defined(MPROTECT_VDB)
+#     if !defined(REDIRECT_MALLOC) && !defined(MAKE_BACK_GRAPH) \
+         && !defined(USE_PROC_FOR_LIBRARIES) && !defined(NO_INCREMENTAL)
         GC_enable_incremental();
-        GC_printf("Switched to incremental mode\n");
-        GC_printf("Emulating dirty bits with mprotect/signals\n");
+#     endif
+      if (GC_is_incremental_mode()) {
+        GC_printf("Switched to incremental mode\n"
+                  "Emulating dirty bits with mprotect/signals\n");
+      }
 #   endif
     GC_set_warn_proc(warn_proc);
     if ((code = pthread_key_create(&fl_key, 0)) != 0) {