frames on the Scheme stack and seal the CStack. Then call
Interpret(). Cannot abort. */
- long int_mask;
-
if (run_callback == SHARP_F)
{
run_callback = find_primitive_cname ("RUN-CALLBACK", false, false, 0);
STACK_PUSH (run_callback);
PUSH_APPLY_FRAME_HEADER (0);
SAVE_CONT();
-
- /* Turn off thread switching. */
- int_mask = GET_INT_MASK;
- SET_INTERRUPT_MASK (int_mask & ~INT_Timer);
Interpret (1);
- SET_INTERRUPT_MASK (int_mask);
-
cstack_depth -= 1;
}
void
callback_run_handler (int callback_id, SCM arglist)
{
- /* Similar to setup_interrupt [utils.c]. Used by callback kernels,
- inside the interpreter. Thus it MAY GC abort.
+ /* Used by callback kernels, inside the interpreter. Thus it MAY GC
+ abort.
Push a Scheme callback handler apply frame. This leaves the
interpreter ready to tail-call the Scheme procedure. (The
fixnum_id = valid_callback_id (callback_id);
stop_history ();
- /* preserve_interrupt_mask ();
-
- The above statement appears in setup_interrupt. In this case,
- something similar is done in callback_run_kernel, BEFORE
- re-entering the interpreter. (The "BEFORE" part is
- important!) */
Will_Push (STACK_ENV_EXTRA_SLOTS + 3);
STACK_PUSH (arglist);
STACK_PUSH (handler);
PUSH_APPLY_FRAME_HEADER (2);
Pushed ();
- /* Turn off interrupts: */
- /* SET_INTERRUPT_MASK (interrupt_mask);
-
- The above statement (from setup_interrupt) must move to
- callback_run_kernel. */
}
static SCM
(if (alien-function? arg)
(alien-function-cache! arg)))
args)
- (without-timer-interrupts
+ (without-interrupts
(lambda ()
(call-alien* alien-function args))))
;;; Malloc/Free
-;; Weak alist of: ( malloc alien X copy for the finalizer )...
+;; Weak alist of: ( malloc alien X copy for c-free )...
(define malloced-aliens '())
-(define (finalize-malloced-aliens)
+(define (free-malloced-aliens)
(let loop ((aliens malloced-aliens)
(prev #f))
(if (pair? aliens)
(set! malloced-aliens '()))
(define (malloc size ctype)
- ;; Add copy to finalizer BEFORE calling malloc.
+ ;; Add copy to malloced-aliens BEFORE calling malloc.
(let ((alien (make-alien ctype))
(copy (make-alien ctype)))
- (set! malloced-aliens (cons (weak-cons alien copy) malloced-aliens))
+ (let ((entry (weak-cons alien copy)))
+ (without-interrupts
+ (lambda ()
+ (set! malloced-aliens (cons entry malloced-aliens)))))
((ucode-primitive c-malloc 2) copy size)
;; Even an interrupt here will not leak a byte.
(copy-alien-address! alien copy)
(let ((copy (weak-cdr weak)))
(without-interrupts
(lambda ()
- (if (not (alien-null? copy))
+ (if (not (alien-null? alien))
(begin
- (alien-null! copy)
+ (alien-null! alien)
((ucode-primitive c-free 1) copy)
- (alien-null! alien))))))))))
+ (alien-null! copy))))))))))
(define (weak-assq obj alist)
(let loop ((alist alist))
(define (callback-handler id args)
;; Installed in the fixed-objects-vector, this procedure is called
- ;; by a callback trampoline, which ensures that timer interrupts are
- ;; masked until the interpreter returns a value.
+ ;; by a callback trampoline. The callout should have already masked
+ ;; all but the GC interrupts.
(if (not (< id (vector-length registered-callbacks)))
(error:bad-range-argument id 'apply-callback))
(define calloutback-stack '())
-(define tracing? #f)
+(define trace? #f)
(define (reset-package!)
(reset-alien-functions!)
(reset-malloced-aliens!)
(reset-callbacks!)
- (set! tracing? #f)
+ (set! trace? #f)
(set! calloutback-stack '()))
(define (initialize-package!)
(reset-package!)
(initialize-callbacks!)
(add-event-receiver! event:after-restore reset-package!)
+ (add-gc-daemon! free-malloced-aliens)
unspecific)
(define-syntax if-tracing
(syntax-rules ()
((_ . BODY)
- (if tracing? ((lambda () . BODY))))))
+ (if trace? ((lambda () . BODY))))))
(define-syntax assert
(syntax-rules ()
(define-syntax trace
(syntax-rules ()
((_ . MSG)
- (if tracing? ((lambda () (outf-console . MSG)))))))
+ (if trace? ((lambda () (outf-console . MSG)))))))
(define (tindent)
(make-string (* 2 (length calloutback-stack)) #\space))
\ No newline at end of file