]> granicus.if.org Git - gc/commitdiff
Add on-heap-resize event notification to API
authorPaolo Molaro <lupus@oddwiz.org>
Mon, 24 Jan 2005 15:29:23 +0000 (15:29 +0000)
committerIvan Maidanski <ivmai@mail.ru>
Fri, 13 Jan 2012 08:02:26 +0000 (12:02 +0400)
(Apply part of commit 3f1314a from 'mono_libgc' branch)

* include/gc.h (GC_on_heap_resize): New API variable declaration.
* alloc.c (GC_on_heap_resize): New global variable.
* alloc.c (GC_finish_collection): Invoke GC_on_heap_resize (if
non-zero) on returning true.

alloc.c
include/gc.h

diff --git a/alloc.c b/alloc.c
index e182af2e4ef707e66e73896f13a046c5017ba029..6131a384324fb3daea2fce6eedb27ad38b8cf8a1 100644 (file)
--- a/alloc.c
+++ b/alloc.c
@@ -780,6 +780,8 @@ 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;
+
 /* Finish up a collection.  Assumes mark bits are consistent, lock is   */
 /* held, but the world is otherwise running.                            */
 STATIC void GC_finish_collection(void)
@@ -1172,6 +1174,9 @@ GC_INNER GC_bool GC_expand_hp_inner(word n)
          GC_heapsize + expansion_slop - 2*MAXHINCR*HBLKSIZE;
       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);
+
     return(TRUE);
 }
 
index 27033dce7266f976b5bbca6c1d1d2edeb2b8d769..355f3026b654ccba2cafa1cb4fe555d711ba924d 100644 (file)
@@ -113,6 +113,9 @@ 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        */
+
 GC_API int GC_find_leak;
                         /* Do not actually garbage collect, but simply  */
                         /* report inaccessible memory that was not      */