From fa62401dff24684f8797bc355807e90d78e880af Mon Sep 17 00:00:00 2001 From: Jonas Echterhoff Date: Thu, 28 May 2020 13:02:00 +0200 Subject: Add GC_set_disable_automatic_collection API to disable automatic periodic collections --- alloc.c | 8 ++++++++ include/gc.h | 1 + 2 files changed, 9 insertions(+) diff --git a/alloc.c b/alloc.c index e125e29b..abf10242 100644 --- a/alloc.c +++ b/alloc.c @@ -367,6 +367,12 @@ STATIC void GC_clear_a_few_frames(void) /* limits used by blacklisting. */ STATIC word GC_collect_at_heapsize = (word)(-1); STATIC GC_bool GC_should_start_incremental_collection = FALSE; +STATIC GC_bool GC_disable_automatic_collection = FALSE; + +GC_API void GC_set_disable_automatic_collection(GC_bool disable) +{ + GC_disable_automatic_collection = disable; +} GC_API void GC_start_incremental_collection() { @@ -391,6 +397,8 @@ GC_INNER GC_bool GC_should_collect(void) GC_should_start_incremental_collection = FALSE; return TRUE; } + if (GC_disable_automatic_collection) + return FALSE; return(GC_adj_bytes_allocd() >= last_min_bytes_allocd || GC_heapsize >= GC_collect_at_heapsize); } diff --git a/include/gc.h b/include/gc.h index 3a4501ae..3d10a9a4 100644 --- a/include/gc.h +++ b/include/gc.h @@ -2038,6 +2038,7 @@ GC_API void GC_CALL GC_start_world_external(void); GC_API void GC_CALL GC_disable_incremental(void); GC_API void GC_CALL GC_start_incremental_collection (void); +GC_API void GC_CALL GC_set_disable_automatic_collection(int); /* APIs for getting access to raw GC heap */ /* These are NOT thread safe, so should be called with GC lock held */ -- cgit v1.2.3