diff options
| author | Andy Wingo <wingo@pobox.com> | 2016-12-22 17:22:58 +0100 |
|---|---|---|
| committer | Andy Wingo <wingo@pobox.com> | 2016-12-22 17:22:58 +0100 |
| commit | ea90f419d3fb08efd28e25063416c672acfc2bb3 (patch) | |
| tree | 58d683600a82ace9c738f8f123505a35f9608354 /fibers | |
| parent | Rework runqueue as pair of stacks (diff) | |
| download | guile-fibers-ea90f419d3fb08efd28e25063416c672acfc2bb3.tar.gz | |
run-scheduler pops one fiber at a time
* fibers/internal.scm (run-scheduler): Pop one fiber at a time.
Diffstat (limited to 'fibers')
| -rw-r--r-- | fibers/internal.scm | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/fibers/internal.scm b/fibers/internal.scm index 4398937..6a39cfe 100644 --- a/fibers/internal.scm +++ b/fibers/internal.scm @@ -282,21 +282,23 @@ file descriptors being waited on, and no more timers pending to run. Return zero values." (let ((next (scheduler-next-runqueue sched)) (cur (scheduler-current-runqueue sched))) - (let lp () + (let next-turn () (schedule-runnables-for-next-turn sched) (stack-push-list! cur (reverse (stack-pop-all! next))) - (match (stack-pop-all! cur) - (() - ;; Could be the scheduler is stopping, or it could be that we - ;; got a spurious wakeup. In any case, this is the place to - ;; check to see whether the scheduler is really done. - (cond - ((not (zero? (scheduler-active-fd-count sched))) (lp)) - ((not (psq-empty? (scheduler-timers sched))) (lp)) - (else (values)))) - (runnables - (for-each run-fiber runnables) - (lp)))))) + (cond + ((stack-empty? cur) + ;; Could be the scheduler is stopping, or it could be that we + ;; got a spurious wakeup. In any case, this is the place to + ;; check to see whether the scheduler is really done. + (cond + ((not (zero? (scheduler-active-fd-count sched))) (next-turn)) + ((not (psq-empty? (scheduler-timers sched))) (next-turn)) + (else (values)))) + (else + (let next-fiber () + (match (stack-pop! cur #f) + (#f (next-turn)) + (fiber (run-fiber fiber) (next-fiber))))))))) (define (steal-work! sched) "Steal some work from @var{sched}. Return a list of runnable fibers |
