From 95ad19e3eafd6b40dfef5ba12a02600f1368b927 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Wed, 1 Feb 2012 21:25:44 +0400 Subject: [PATCH] Add GC_is_disabled new function to GC API * include/gc.h (GC_dont_gc): Improve comment (add note for new client code). * include/gc.h (GC_is_disabled): New API function. * misc.c (GC_is_disabled): Likewise. --- include/gc.h | 11 ++++++++--- misc.c | 5 +++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/include/gc.h b/include/gc.h index ddb363a4..56024c85 100644 --- a/include/gc.h +++ b/include/gc.h @@ -195,9 +195,10 @@ GC_API int GC_dont_gc; /* != 0 ==> Don't collect. In versions 6.2a1+, */ /* Used as a counter, so that nested enabling */ /* and disabling work correctly. Should */ /* normally be updated with GC_enable() and */ - /* GC_disable() calls. */ - /* Direct assignment to GC_dont_gc is */ - /* deprecated. */ + /* GC_disable() calls. Direct assignment to */ + /* GC_dont_gc is deprecated. To check whether */ + /* GC is disabled, GC_is_disabled() is */ + /* preferred for new code. */ GC_API int GC_dont_expand; /* Don't expand the heap unless explicitly */ @@ -590,6 +591,10 @@ GC_API void GC_CALL GC_get_heap_usage_safe(GC_word * /* pheap_size */, /* ineffective. */ GC_API void GC_CALL GC_disable(void); +/* Return non-zero (TRUE) if and only if garbage collection is disabled */ +/* (i.e., GC_dont_gc value is non-zero). Does not acquire the lock. */ +GC_API int GC_CALL GC_is_disabled(void); + /* Re-enable garbage collection. GC_disable() and GC_enable() calls */ /* nest. Garbage collection is enabled if the number of calls to both */ /* both functions is equal. */ diff --git a/misc.c b/misc.c index 03011958..5dadaab2 100644 --- a/misc.c +++ b/misc.c @@ -1473,6 +1473,11 @@ GC_API void GC_CALL GC_disable(void) UNLOCK(); } +GC_API int GC_CALL GC_is_disabled(void) +{ + return GC_dont_gc != 0; +} + /* Helper procedures for new kind creation. */ GC_API void ** GC_CALL GC_new_free_list_inner(void) { -- 2.40.0