X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fcode%2Fgc.lisp;h=7945c279a07079251bf04adb1524fa591ddf2371;hb=a7002797a1fb36ec3a7c30f6ebcb314b0e58e817;hp=cf5451eec0d15b37276dbc7f68c734bc1d94830b;hpb=9b458bf995314b7edd1cc050bd11ede83ada4328;p=sbcl.git diff --git a/src/code/gc.lisp b/src/code/gc.lisp index cf5451e..7945c27 100644 --- a/src/code/gc.lisp +++ b/src/code/gc.lisp @@ -120,7 +120,10 @@ (defun gc-reinit () (gc-on) (gc) - (setf *n-bytes-freed-or-purified* 0)) + (setf *n-bytes-freed-or-purified* 0 + *gc-run-time* 0 + ;; See comment in interr.lisp + *heap-exhausted-error-condition* (make-condition 'heap-exhausted-error))) (declaim (ftype (function () unsigned-byte) get-bytes-consed)) (defun get-bytes-consed () @@ -137,8 +140,9 @@ and submit it as a patch." ;;;; GC hooks (defvar *after-gc-hooks* nil - "Called after each garbage collection. In a multithreaded -environment these hooks may run in any thread.") + "Called after each garbage collection, except for garbage collections +triggered during thread exits. In a multithreaded environment these hooks may +run in any thread.") ;;;; internal GC @@ -211,12 +215,22 @@ environment these hooks may run in any thread.") ;; Outside the mutex, these may cause another GC. FIXME: it can ;; potentially exceed maximum interrupt nesting by triggering ;; GCs. - (run-pending-finalizers) - (dolist (hook *after-gc-hooks*) - (handler-case - (funcall hook) - (error (c) - (warn "Error calling after GC hook ~S:~% ~S" hook c))))))) + ;; + ;; Can that be avoided by having the finalizers and hooks run only + ;; from the outermost SUB-GC? + ;; + ;; KLUDGE: Don't run the hooks in GC's triggered by dying threads, + ;; so that user-code never runs with + ;; (thread-alive-p *current-thread*) => nil + ;; The long-term solution will be to keep a separate thread for + ;; finalizers and after-gc hooks. + (when (sb!thread:thread-alive-p sb!thread:*current-thread*) + (run-pending-finalizers) + (dolist (hook *after-gc-hooks*) + (handler-case + (funcall hook) + (error (c) + (warn "Error calling after-GC hook ~S:~% ~A" hook c)))))))) ;;; This is the user-advertised garbage collection function. (defun gc (&key (gen 0) (full nil) &allow-other-keys)