@@ -4,11 +4,13 @@ let[@inline never] quota_non_positive () = invalid_arg "quota must be positive"
4
4
5
5
type ready =
6
6
| Spawn of Fiber .t * (Fiber .t -> unit )
7
- | Continue of Fiber .t * (unit , unit ) Effect.Deep .continuation
7
+ | Continue of Fiber .t * (unit , unit ) Effect.Shallow .continuation
8
8
| Resume of
9
9
Fiber .t
10
- * ((exn * Printexc .raw_backtrace ) option , unit ) Effect.Deep .continuation
11
- | Return of Fiber.Maybe .t * (unit , unit ) Effect.Deep .continuation
10
+ * ( (exn * Printexc .raw_backtrace ) option ,
11
+ unit )
12
+ Effect.Shallow .continuation
13
+ | Return of Fiber.Maybe .t * (unit , unit ) Effect.Shallow .continuation
12
14
13
15
module Mpscq = Picos_aux_mpscq
14
16
@@ -20,13 +22,13 @@ type t = {
20
22
resume :
21
23
Trigger .t ->
22
24
Fiber .t ->
23
- ((exn * Printexc .raw_backtrace ) option , unit ) Effect.Deep .continuation ->
25
+ ((exn * Printexc .raw_backtrace ) option , unit ) Effect.Shallow .continuation ->
24
26
unit ;
25
- current : ((Fiber .t , unit ) Effect.Deep .continuation -> unit ) option ;
26
- yield : ((unit , unit ) Effect.Deep .continuation -> unit ) option ;
27
- return : ((unit , unit ) Effect.Deep .continuation -> unit ) option ;
28
- discontinue : ((unit , unit ) Effect.Deep .continuation -> unit ) option ;
29
- handler : (unit , unit ) Effect.Deep .handler ;
27
+ current : ((Fiber .t , unit ) Effect.Shallow .continuation -> unit ) option ;
28
+ yield : ((unit , unit ) Effect.Shallow .continuation -> unit ) option ;
29
+ return : ((unit , unit ) Effect.Shallow .continuation -> unit ) option ;
30
+ discontinue : ((unit , unit ) Effect.Shallow .continuation -> unit ) option ;
31
+ handler : (unit , unit ) Effect.Shallow .handler ;
30
32
quota : int ;
31
33
mutable fiber : Fiber.Maybe .t ;
32
34
mutable remaining_quota : int ;
@@ -38,19 +40,20 @@ let rec next t =
38
40
| Spawn (fiber , main ) ->
39
41
t.fiber < - Fiber.Maybe. of_fiber fiber;
40
42
t.remaining_quota < - t.quota;
41
- Effect.Deep. match_with main fiber t.handler
43
+ let k = Effect.Shallow. fiber main in
44
+ Effect.Shallow. continue_with k fiber t.handler
42
45
| Return (fiber , k ) ->
43
46
t.fiber < - fiber;
44
47
t.remaining_quota < - t.quota;
45
- Effect.Deep. continue k ()
48
+ Effect.Shallow. continue_with k () t.handler
46
49
| Continue (fiber , k ) ->
47
50
t.fiber < - Fiber.Maybe. of_fiber fiber;
48
51
t.remaining_quota < - t.quota;
49
- Fiber. continue fiber k ()
52
+ Fiber. continue_with fiber k () t.handler
50
53
| Resume (fiber , k ) ->
51
54
t.fiber < - Fiber.Maybe. of_fiber fiber;
52
55
t.remaining_quota < - t.quota;
53
- Fiber. resume fiber k
56
+ Fiber. resume_with fiber k t.handler
54
57
| exception Mpscq. Empty ->
55
58
t.fiber < - Fiber.Maybe. nothing;
56
59
if t.num_alive_fibers <> 0 then begin
@@ -102,7 +105,7 @@ let run_fiber ?quota ?fatal_exn_handler:(exnc : _ = raise) fiber main =
102
105
Some
103
106
(fun k ->
104
107
let fiber = Fiber.Maybe. to_fiber t.fiber in
105
- Effect.Deep. continue k fiber)
108
+ Effect.Shallow. continue_with k fiber t.handler )
106
109
and yield =
107
110
Some
108
111
(fun k ->
@@ -115,7 +118,7 @@ let run_fiber ?quota ?fatal_exn_handler:(exnc : _ = raise) fiber main =
115
118
let remaining_quota = t.remaining_quota - 1 in
116
119
if 0 < remaining_quota then begin
117
120
t.remaining_quota < - remaining_quota;
118
- Effect.Deep. continue k ()
121
+ Effect.Shallow. continue_with k () t.handler
119
122
end
120
123
else begin
121
124
Mpscq. push t.ready (Return (t.fiber, k));
@@ -125,10 +128,10 @@ let run_fiber ?quota ?fatal_exn_handler:(exnc : _ = raise) fiber main =
125
128
Some
126
129
(fun k ->
127
130
let fiber = Fiber.Maybe. to_fiber t.fiber in
128
- Fiber. continue fiber k () )
131
+ Fiber. continue_with fiber k () t.handler )
129
132
and handler = { retc; exnc; effc }
130
133
and [@ alert " -handler" ] effc :
131
- type a. a Effect.t -> ((a, _) Effect.Deep .continuation -> _) option =
134
+ type a. a Effect.t -> ((a, _) Effect.Shallow .continuation -> _) option =
132
135
function
133
136
| Fiber .Current -> t .current
134
137
| Fiber .Spawn r ->
@@ -150,7 +153,9 @@ let run_fiber ?quota ?fatal_exn_handler:(exnc : _ = raise) fiber main =
150
153
| () -> t.return
151
154
| exception exn ->
152
155
let bt = Printexc. get_raw_backtrace () in
153
- Some (fun k -> Effect.Deep. discontinue_with_backtrace k exn bt)
156
+ Some
157
+ (fun k ->
158
+ Effect.Shallow. discontinue_with_backtrace k exn bt t.handler)
154
159
end
155
160
| Trigger. Await trigger ->
156
161
Some
@@ -161,7 +166,7 @@ let run_fiber ?quota ?fatal_exn_handler:(exnc : _ = raise) fiber main =
161
166
let remaining_quota = t.remaining_quota - 1 in
162
167
if 0 < remaining_quota then begin
163
168
t.remaining_quota < - remaining_quota;
164
- Fiber. resume fiber k
169
+ Fiber. resume_with fiber k t.handler
165
170
end
166
171
else begin
167
172
Mpscq. push t.ready (Resume (fiber, k));
0 commit comments