(hook/gc-finish start-value space-remaining)
((ucode-primitive request-interrupts! 1) interrupt-bit/after-gc))
-(define (abort-if-heap-low space-remaining)
- (if (< space-remaining 4096)
- (if gc-boot-loading?
- (let ((console ((ucode-primitive tty-output-channel 0))))
- ((ucode-primitive channel-write 4)
- console
- gc-boot-death-message
- 0
- ((ucode-primitive string-length 1) gc-boot-death-message))
- ((ucode-primitive exit-with-value 1) #x14))
- (abort->nearest
- (cmdl-message/append
- (cmdl-message/strings "Aborting!: out of memory")
- ;; Clean up whatever possible to avoid a reoccurrence.
- (cmdl-message/active
- (lambda (port)
- port
- (with-gc-notification! #t gc-clean))))))))
+(define (abort-heap-low)
+ (if gc-boot-loading?
+ (let ((console ((ucode-primitive tty-output-channel 0))))
+ ((ucode-primitive channel-write 4)
+ console
+ gc-boot-death-message
+ 0
+ ((ucode-primitive string-length 1) gc-boot-death-message))
+ ((ucode-primitive exit-with-value 1) #x14))
+ (abort->nearest
+ (cmdl-message/append
+ (cmdl-message/strings "Aborting!: out of memory")
+ ;; Clean up whatever possible to avoid a reoccurrence.
+ (cmdl-message/active
+ (lambda (port)
+ port
+ (with-gc-notification! #t gc-clean)))))))
(define gc-boot-loading?)
(define (signal-gc-events)
(let ((statistic last-statistic))
- (for-each
- (lambda (entry)
- (let ((thread (weak-car entry))
- (event (weak-cdr entry)))
- (if (and thread event)
- (without-interrupts
- (lambda ()
- (if (not (eq? 'DEAD (thread-execution-state thread)))
- (%signal-thread-event
- thread
- (named-lambda (gc-event)
- (abort-if-heap-low (gc-statistic/heap-left statistic))
- (event statistic)))))))))
- gc-events)))
+ (if (< (gc-statistic/heap-left statistic) 4096)
+ (begin
+ (for-each
+ (lambda (entry)
+ (let ((thread (weak-car entry))
+ (event (weak-cdr entry)))
+ (if (and thread event)
+ (signal-event thread abort-heap-low))))
+ gc-events)
+ (let ((console-thread
+ (thread-mutex-owner (port/thread-mutex console-i/o-port))))
+ (if (not (weak-assq console-thread gc-events))
+ (signal-event console-thread abort-heap-low))))
+ (for-each
+ (lambda (entry)
+ (let ((thread (weak-car entry))
+ (event (weak-cdr entry)))
+ (if (and thread event)
+ (signal-event thread (named-lambda (gc-event)
+ (event statistic))))))
+ gc-events))))
+
+(define (signal-event thread event)
+ (without-interrupts
+ (lambda ()
+ (if (not (eq? 'DEAD (thread-execution-state thread)))
+ (%signal-thread-event thread event)))))
(define (weak-assq obj alist)
(let loop ((alist alist))
(export (runtime error-handler)
hook/hardware-trap)
(export (runtime gc-notification)
- abort-if-heap-low)
+ abort-heap-low)
(initialization (initialize-package!)))
(define-package (runtime gc-daemons)