summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2017-01-08 17:17:42 +0100
committerAndy Wingo <wingo@pobox.com>2017-01-08 17:17:42 +0100
commit8aa6ac0a6c6a86492d3f351a312d264216fbd2e5 (patch)
tree91f1b967f80f3b0236535300ba5a2f3656ca560f
parentEnable preemption by default (diff)
downloadguile-fibers-8aa6ac0a6c6a86492d3f351a312d264216fbd2e5.tar.gz
create-fiber always captures dynamic state
* fibers/internal.scm (create-fiber): Remove dynamic-state argument; always capture the current dynamic state. * fibers/timers.scm (timer-operation): * fibers.scm (spawn-fiber): Adapt.
-rw-r--r--fibers.scm3
-rw-r--r--fibers/internal.scm19
-rw-r--r--fibers/timers.scm3
3 files changed, 12 insertions, 13 deletions
diff --git a/fibers.scm b/fibers.scm
index 270c912..2f7c997 100644
--- a/fibers.scm
+++ b/fibers.scm
@@ -108,8 +108,7 @@
(vector-ref remote idx))))
(define (spawn sched thunk)
(create-fiber (if parallel? (choose-sched sched) sched)
- thunk
- (current-dynamic-state)))
+ thunk))
(cond
(sched
;; When a scheduler is passed explicitly, it could be there is no
diff --git a/fibers/internal.scm b/fibers/internal.scm
index c4d75a6..99727f6 100644
--- a/fibers/internal.scm
+++ b/fibers/internal.scm
@@ -333,17 +333,18 @@ stolen."
(for-each kill-fiber (list-copy (scheduler-fibers sched)))
(epoll-destroy (scheduler-epfd sched)))
-(define (create-fiber sched thunk dynamic-state)
+(define (create-fiber sched thunk)
"Spawn a new fiber in @var{sched} with the continuation @var{thunk}.
-The fiber will be scheduled on the next turn. During the fiber's
-extent, @var{dynamic-state} will be made current, isolating fluid and
-parameter mutations to this fiber."
+The fiber will be scheduled on the next turn. @var{thunk} will run
+with a copy of the current dynamic state, isolating fluid and
+parameter mutations to the fiber."
(let* ((fiber (make-fiber sched #f))
- (thunk (lambda ()
- (with-dynamic-state dynamic-state
- (lambda ()
- (current-fiber fiber)
- (thunk))))))
+ (thunk (let ((dynamic-state (current-dynamic-state)))
+ (lambda ()
+ (with-dynamic-state dynamic-state
+ (lambda ()
+ (current-fiber fiber)
+ (thunk)))))))
(nameset-add! fibers-nameset fiber)
(schedule-fiber! fiber thunk)))
diff --git a/fibers/timers.scm b/fibers/timers.scm
index 15638b0..1ccd088 100644
--- a/fibers/timers.scm
+++ b/fibers/timers.scm
@@ -61,8 +61,7 @@ units. The operation will succeed with no values."
(create-fiber (timer-sched)
(lambda ()
(perform-operation (timer-operation expiry))
- (timer))
- (current-dynamic-state))))))
+ (timer)))))))
(define (wait-operation seconds)
"Make an operation that will succeed with no values when