1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-07-02 23:50:47 +02:00

Replace after-gc-hook with {add,remove}-after-gc-callback!

* libguile/gc.c:
(scm_gc_event_listener_restarting_mutators):
(after_gc_async_thunk):
(scm_init_gc): Instead of using a hook for after-gc callbacks, just use
a list of thunks.  Will allow us to move hooks to Scheme.
(add-after-gc-callback!, remove-after-gc-callback!): New functions.
* libguile/gc.h (scm_after_gc_hook): Remove.
* libguile/scmsigs.c (signal_delivery_thread): Update comment.
* module/statprof.scm (gcprof):
* test-suite/tests/gc.test ("gc"): Update to use new functions.
This commit is contained in:
Andy Wingo 2025-06-16 10:01:16 +02:00
parent f436e550ea
commit 04fdc33a54
6 changed files with 41 additions and 23 deletions

View file

@ -139,7 +139,7 @@ the allocation limit."
(lambda ()
(dynamic-wind
(lambda ()
(add-hook! after-gc-hook check-allocation))
(add-after-gc-callback! check-allocation))
(lambda ()
(call-with-stack-overflow-handler
;; The limit is in "words", which used to be 4 or 8 but now
@ -148,7 +148,7 @@ the allocation limit."
thunk
(lambda () (abort-to-prompt tag))))
(lambda ()
(remove-hook! after-gc-hook check-allocation))))
(remove-after-gc-callback! check-allocation))))
(lambda (k)
(limit-reached)))))

View file

@ -1,7 +1,7 @@
;;;; (statprof) -- a statistical profiler for Guile
;;;; -*-scheme-*-
;;;;
;;;; Copyright (C) 2009, 2010, 2011, 2013-2018, 2020 Free Software Foundation, Inc.
;;;; Copyright (C) 2009, 2010, 2011, 2013-2018, 2020, 2025 Free Software Foundation, Inc.
;;;; Copyright (C) 2004, 2009 Andy Wingo <wingo at pobox dot com>
;;;; Copyright (C) 2001 Rob Browning <rlb at defaultvalue dot org>
;;;;
@ -888,14 +888,14 @@ times."
(set-profile-level! state 1)
(set-last-start-time! state (get-internal-run-time))
(set-gc-time-taken! state (assq-ref (gc-stats) 'gc-time-taken))
(add-hook! after-gc-hook gc-callback))
(add-after-gc-callback! gc-callback))
(lambda ()
(let lp ((i loop))
(unless (zero? i)
(call-thunk thunk)
(lp (1- i)))))
(lambda ()
(remove-hook! after-gc-hook gc-callback)
(remove-after-gc-callback! gc-callback)
(set-gc-time-taken! state
(- (assq-ref (gc-stats) 'gc-time-taken)
(gc-time-taken state)))