]> granicus.if.org Git - gc/commitdiff
Add setter and getter for GC_on_heap_resize;
authorIvan Maidanski <ivmai@mail.ru>
Fri, 13 Jan 2012 04:55:21 +0000 (08:55 +0400)
committerIvan Maidanski <ivmai@mail.ru>
Fri, 13 Jan 2012 10:23:36 +0000 (14:23 +0400)
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
include/gc.h
misc.c

diff --git a/alloc.c b/alloc.c
index 6131a384324fb3daea2fce6eedb27ad38b8cf8a1..6ba3151ce13d93366e52c6c8c95d0468093899f7 100644 (file)
--- 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);
 }
index 355f3026b654ccba2cafa1cb4fe555d711ba924d..10e93afbc9670d014fd5966e430872e5dcc03add 100644 (file)
@@ -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 a26de350fd095279549083aece19d1cd48628274..e4f31b92399d918d8e1aeb75594a572069f7c7fa 100644 (file)
--- 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). */