Fixed memory leak.

This commit is contained in:
mainzelm 2002-02-07 10:11:20 +00:00
parent 73b11ef47f
commit 6158e7a964
1 changed files with 17 additions and 10 deletions

View File

@ -485,7 +485,7 @@
(next (make-placeholder)) (next (make-placeholder))
prev) prev)
(define reaped-proc-tail (make-placeholder)) (define reaped-proc-tail (make-reaped-proc (make-weak-pointer #f) 'head))
(define reaped-proc-head reaped-proc-tail) (define reaped-proc-head reaped-proc-tail)
(define reaped-proc-push-lock (make-lock)) (define reaped-proc-push-lock (make-lock))
(define reaped-proc-pop-lock (make-lock)) ;;; Zippy sez: pop lock! (define reaped-proc-pop-lock (make-lock)) ;;; Zippy sez: pop lock!
@ -493,22 +493,29 @@
(define (push-reaped-proc proc) (define (push-reaped-proc proc)
(obtain-lock reaped-proc-push-lock) (obtain-lock reaped-proc-push-lock)
(let ((push-me (make-reaped-proc (make-weak-pointer proc) reaped-proc-tail))) (let ((push-me (make-reaped-proc (make-weak-pointer proc) reaped-proc-tail)))
(placeholder-set! reaped-proc-tail push-me) (placeholder-set! (reaped-proc:next reaped-proc-tail) push-me)
; (add-finalizer! proc (lambda ignore (remove-reaped-proc push-me))) (add-finalizer! proc (make-reaped-proc-finalizer push-me))
(set! reaped-proc-tail (reaped-proc:next push-me))) (set! reaped-proc-tail push-me))
(release-lock reaped-proc-push-lock)) (release-lock reaped-proc-push-lock))
(define (make-reaped-proc-finalizer push-me)
(lambda ignore
(remove-reaped-proc push-me)))
(define (remove-reaped-proc reaped-proc) (define (remove-reaped-proc reaped-proc)
(spawn (lambda () ;This is blocking, so should run by itself (spawn (lambda () ;This is blocking, so should run by itself
(placeholder-set! (reaped-proc:prev reaped-proc) (set-reaped-proc:prev
(placeholder-value (placeholder-value (reaped-proc:next reaped-proc))
(reaped-proc:next reaped-proc)))) (reaped-proc:prev reaped-proc))
"reaped-proc-removing-thread")) (set-reaped-proc:next
(reaped-proc:prev reaped-proc)
(reaped-proc:next reaped-proc)))
"reaped-proc-removing-thread"))
(define (pop-reaped-proc) (define (pop-reaped-proc)
(obtain-lock reaped-proc-pop-lock) ;;; pop lock pop lock pop lock! (obtain-lock reaped-proc-pop-lock) ;;; pop lock pop lock pop lock!
(let ((pop-me (placeholder-value reaped-proc-head))) (let ((pop-me (placeholder-value (reaped-proc:next reaped-proc-head))))
(set! reaped-proc-head (reaped-proc:next pop-me)) (set! reaped-proc-head pop-me)
(release-lock reaped-proc-pop-lock) (release-lock reaped-proc-pop-lock)
(weak-pointer-ref (reaped-proc:proc pop-me)))) (weak-pointer-ref (reaped-proc:proc pop-me))))