From 1d519e5957c8b7bdc287a39f711aa9d57ed1b890 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Fri, 13 Jan 2012 08:55:21 +0400 Subject: [PATCH] Add setter and getter for GC_on_heap_resize; change GC_on_heap_resize argument type from size_t to GC_word * include/gc.h (GC_on_heap_resize_proc): Declare new type. * alloc.c (GC_on_heap_resize): Change type to GC_on_heap_resize_proc (which uses GC_word argument instead of size_t and GC_CALLBACK calling conventions). * include/gc.h (GC_on_heap_resize): Likewise. * alloc.c (GC_expand_hp_inner): Do not cast GC_heapsize value in GC_on_heap_resize call. * include/gc.h (GC_on_heap_resize): Refine comment. * include/gc.h (GC_set_on_heap_resize, GC_get_on_heap_resize): New API functions. * misc.c (GC_set_on_heap_resize, GC_get_on_heap_resize): Likewise. --- alloc.c | 4 ++-- include/gc.h | 11 +++++++++-- misc.c | 19 +++++++++++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/alloc.c b/alloc.c index 6131a384..6ba3151c 100644 --- a/alloc.c +++ b/alloc.c @@ -780,7 +780,7 @@ STATIC void GC_clear_fl_marks(ptr_t q) void GC_check_tls(void); #endif -void (*GC_on_heap_resize)(size_t new_size) = 0; +GC_on_heap_resize_proc GC_on_heap_resize = 0; /* Finish up a collection. Assumes mark bits are consistent, lock is */ /* held, but the world is otherwise running. */ @@ -1175,7 +1175,7 @@ GC_INNER GC_bool GC_expand_hp_inner(word n) if (GC_collect_at_heapsize < GC_heapsize /* wrapped */) GC_collect_at_heapsize = (word)(-1); if (GC_on_heap_resize) - (*GC_on_heap_resize)((size_t)GC_heapsize); + (*GC_on_heap_resize)(GC_heapsize); return(TRUE); } diff --git a/include/gc.h b/include/gc.h index 355f3026..10e93afb 100644 --- a/include/gc.h +++ b/include/gc.h @@ -113,8 +113,15 @@ GC_API GC_oom_func GC_oom_fn; GC_API void GC_CALL GC_set_oom_fn(GC_oom_func); GC_API GC_oom_func GC_CALL GC_get_oom_fn(void); -GC_API void (*GC_on_heap_resize)(size_t /* new_size */); - /* Invoked when the heap grows or shrinks */ +typedef void (GC_CALLBACK * GC_on_heap_resize_proc)(GC_word /* new_size */); +GC_API GC_on_heap_resize_proc GC_on_heap_resize; + /* Invoked when the heap grows or shrinks. */ + /* Called with the world stopped (and the */ + /* allocation lock held). May be 0. */ +GC_API void GC_CALL GC_set_on_heap_resize(GC_on_heap_resize_proc); +GC_API GC_on_heap_resize_proc GC_CALL GC_get_on_heap_resize(void); + /* Both the supplied setter and the getter */ + /* acquire the GC lock (to avoid data races). */ GC_API int GC_find_leak; /* Do not actually garbage collect, but simply */ diff --git a/misc.c b/misc.c index a26de350..e4f31b92 100644 --- a/misc.c +++ b/misc.c @@ -1715,6 +1715,25 @@ GC_API GC_oom_func GC_CALL GC_get_oom_fn(void) return fn; } +GC_API void GC_CALL GC_set_on_heap_resize(GC_on_heap_resize_proc fn) +{ + /* fn may be 0 (means no event notifier). */ + DCL_LOCK_STATE; + LOCK(); + GC_on_heap_resize = fn; + UNLOCK(); +} + +GC_API GC_on_heap_resize_proc GC_CALL GC_get_on_heap_resize(void) +{ + GC_on_heap_resize_proc fn; + DCL_LOCK_STATE; + LOCK(); + fn = GC_on_heap_resize; + UNLOCK(); + return fn; +} + GC_API void GC_CALL GC_set_finalizer_notifier(GC_finalizer_notifier_proc fn) { /* fn may be 0 (means no finalizer notifier). */ -- 2.40.0