1-- The hosted provider's `fibre.scheduler` (D444): the blocking host runs
2-- each task to its end, on the caller's stack, before `start` returns,
3-- as `fibre.whole` does. Its calls block the thread, so it has nothing
4-- to yield to and is no provider of `fibre.turns`; a program that needs
5-- turns makes a round, or an Io that waits for events, instead. It
6-- imports core/fibre and not its switch, so every hosted target admits
7-- it whether or not its backend switches stacks.
8
9import core/fibre
10import core/mem
11
12fibre_start: (self: host, escaping record: ptr mut fibre.space,
13 escaping stack: []mut u8, escaping work: any fibre.task)
14 -> none ! mem.out_of_memory =
15 _ = self
16 _ = stack
17 record.val.status = 1
18 work.run()
19 record.val.status = 0
20end fibre_start
21
22fibre_finished: (self: host, record: fibre.space) -> (yes: bool) =
23 _ = self
24 yes = record.status == 0
25end fibre_finished
26
27-- Nothing is ever running when `start` has returned.
28fibre_wait: (self: host) -> none =
29 _ = self
30end fibre_wait
31
32host is fibre.scheduler (start: fibre_start, finished: fibre_finished,
33 wait: fibre_wait)