Process pending thread events when unblocking them.
authorTaylor R Campbell <campbell@mumble.net>
Wed, 29 May 2019 04:10:57 +0000 (04:10 +0000)
committerTaylor R Campbell <campbell@mumble.net>
Wed, 29 May 2019 04:58:12 +0000 (04:58 +0000)
Partly fixes bug where profiler never got a chance to run when the
program was doing most of its work in short routines that block and
unblock thread events, like opening and closing files.

Only partly, because it seems something else unblocks thread events
without processing them -- until we do another block/unblock cycle as
in channel-close.  Verified that very little time is actually spent
in channel-close; haven't yet tracked down who the culprit is.

src/runtime/thread.scm

index d030a2925296d0c0d23a7ebeff5ab24ca60a24a0..954d00d4283d9ca14ea7363808c168a0f1b1ea25 100644 (file)
@@ -897,9 +897,7 @@ USA.
                        value))
                    'with-thread-events-blocked
                    block-events?)))
-             (let ((thread first-running-thread))
-               (if thread
-                   (set-thread/block-events?! thread block-events?)))
+             (%set-thread-event-block! block-events?)
              (set-interrupt-enables! interrupt-mask)
              value))
          (begin
@@ -917,10 +915,16 @@ USA.
 (define (set-thread-event-block! block?)
   (without-interrupts
    (lambda ()
-     (let ((thread first-running-thread))
-       (if thread
-          (set-thread/block-events?! thread block?)))
-     unspecific)))
+     (%set-thread-event-block! block?))))
+
+(define (%set-thread-event-block! block?)
+  (let ((thread first-running-thread))
+    (if thread
+       (begin
+         (if (not block?)
+             (handle-thread-events thread))
+         (set-thread/block-events?! thread block?))))
+  unspecific)
 \f
 (define (signal-thread-event thread event #!optional no-error?)
   (guarantee thread? thread 'signal-thread-event)