From 86a4ee915f3dcd4241882e4ff9b8564b56714451 Mon Sep 17 00:00:00 2001 From: ivmai Date: Fri, 12 Mar 2010 20:43:11 +0000 Subject: [PATCH] 2010-03-12 Ivan Maidanski * alloc.c (GC_start_call_back): Replace the definition type to GC_start_callback_proc. * alloc.c (GC_set_start_callback, GC_get_start_callback): New setter/getter function. * alloc.c (GC_try_to_collect_inner): Call GC_notify_full_gc() unconditionally (because GC_try_to_collect_inner always does full GC). * include/gc_mark.h (GC_start_callback_proc): New type. * include/gc_mark.h (GC_set_start_callback, GC_get_start_callback): New API function declaration. --- ChangeLog | 13 +++++++++++++ alloc.c | 22 ++++++++++++++++++++-- include/gc_mark.h | 7 +++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index c35fda85..68db4abe 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2010-03-12 Ivan Maidanski + + * alloc.c (GC_start_call_back): Replace the definition type to + GC_start_callback_proc. + * alloc.c (GC_set_start_callback, GC_get_start_callback): New + setter/getter function. + * alloc.c (GC_try_to_collect_inner): Call GC_notify_full_gc() + unconditionally (because GC_try_to_collect_inner always does full + GC). + * include/gc_mark.h (GC_start_callback_proc): New type. + * include/gc_mark.h (GC_set_start_callback, + GC_get_start_callback): New API function declaration. + 2010-03-12 Ivan Maidanski * doc/README.macros (USE_GET_STACKBASE_FOR_MAIN): Document. diff --git a/alloc.c b/alloc.c index eee0ca5a..78011a46 100644 --- a/alloc.c +++ b/alloc.c @@ -303,11 +303,29 @@ GC_INNER GC_bool GC_should_collect(void) || GC_heapsize >= GC_collect_at_heapsize); } -/* STATIC */ void (*GC_start_call_back) (void) = 0; +/* STATIC */ GC_start_callback_proc GC_start_call_back = 0; /* Called at start of full collections. */ /* Not called if 0. Called with the allocation */ /* lock held. Not used by GC itself. */ +GC_API void GC_CALL GC_set_start_callback(GC_start_callback_proc fn) +{ + DCL_LOCK_STATE; + LOCK(); + GC_start_call_back = fn; + UNLOCK(); +} + +GC_API GC_start_callback_proc GC_CALL GC_get_start_callback(void) +{ + GC_start_callback_proc fn; + DCL_LOCK_STATE; + LOCK(); + fn = GC_start_call_back; + UNLOCK(); + return fn; +} + GC_INLINE void GC_notify_full_gc(void) { if (GC_start_call_back != 0) { @@ -407,7 +425,7 @@ GC_INNER GC_bool GC_try_to_collect_inner(GC_stop_func stop_func) GC_collect_a_little_inner(1); } } - if (stop_func == GC_never_stop_func) GC_notify_full_gc(); + GC_notify_full_gc(); # ifndef SMALL_CONFIG if (GC_print_stats) { GET_TIME(start_time); diff --git a/include/gc_mark.h b/include/gc_mark.h index e3a09a52..420e4702 100644 --- a/include/gc_mark.h +++ b/include/gc_mark.h @@ -211,6 +211,13 @@ GC_API void GC_CALL GC_register_describe_type_fn(int /* kind */, GC_API size_t GC_CALL GC_get_heap_size_inner(void); GC_API size_t GC_CALL GC_get_free_bytes_inner(void); +/* Set and get the client notifier on collections. The client function */ +/* is called at the start of every full GC (called with the allocation */ +/* lock held). May be 0. */ +typedef void (GC_CALLBACK * GC_start_callback_proc)(void); +GC_API void GC_CALL GC_set_start_callback(GC_start_callback_proc); +GC_API GC_start_callback_proc GC_CALL GC_get_start_callback(void); + #ifdef __cplusplus } /* end of extern "C" */ #endif -- 2.40.0