diff --git a/scsh/low-interrupt.scm b/scsh/low-interrupt.scm index 8831aac..09c582c 100644 --- a/scsh/low-interrupt.scm +++ b/scsh/low-interrupt.scm @@ -59,17 +59,41 @@ + (define (init-low-interrupt) - (set-interrupt-handler! - (enum interrupt os-signal) - (lambda (type arg enabled-interrupts) - (call-handlers type enabled-interrupts))) - - (set-interrupt-handler! - (enum interrupt keyboard) - (lambda (enabled-interrupts) - (call-handlers (enum low-interrupt keyboard) enabled-interrupts))) - + (spawn + (lambda () + (let ((I (current-thread))) + (set-interrupt-handler! + (enum interrupt os-signal) + (lambda (type arg enabled-interrupts) + (schedule-event I + (enum event-type interrupt) + (enum interrupt os-signal) + type + enabled-interrupts))) + (set-interrupt-handler! + (enum interrupt keyboard) + (lambda (enabled-interrupts) + (schedule-event I + (enum event-type interrupt) + (enum interrupt keyboard) + enabled-interrupts))) + (let loop () + (wait) + (call-with-values + get-next-event! + (lambda (event . data) + (if (eq? event (enum event-type interrupt)) + (let ((i-nr (car data))) + (if (eq? i-nr (enum interrupt os-signal)) + (call-handlers (cadr data) (caddr data)) + (if (eq? i-nr (enum interrupt keyboard)) + (call-handlers (enum low-interrupt keyboard) + (cadr data)))))))) + (loop)))) + 'low-interrupt-deliver-thread) + (call-after-gc! (lambda () (let ((enabled-interrupts "JMG: enabled interrupts not yet impl")) @@ -83,11 +107,9 @@ (define interrupt-deliver-lock (make-lock)) (define (call-handlers low-interrupt enabled-interrupts) - (obtain-lock interrupt-deliver-lock) (for-each (lambda (handler-lock-pair) ((car handler-lock-pair) enabled-interrupts)) - (low-interrupt-handler-ref low-interrupt)) - (release-lock interrupt-deliver-lock)) + (low-interrupt-handler-ref low-interrupt))) ;;; the vm uses the timer for the scheduler