Skip to content

Commit 35b93c0

Browse files
committed
Use Single_waiter in Switch
This is more efficient, and is also a step towards removing Waiters completely.
1 parent dcf8624 commit 35b93c0

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

lib_eio/core/single_waiter.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
(* A simplified version of [Waiters] that can only handle one waiter and is not thread-safe. *)
1+
(* Allows a single fiber to wait to be notified by another fiber in the same domain.
2+
If multiple fibers need to wait at once, or the notification comes from another domain,
3+
this can't be used. *)
24

35
type 'a t = {
46
mutable wake : ('a, exn) result -> unit;

lib_eio/core/switch.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ type t = {
44
mutable daemon_fibers : int;
55
mutable exs : (exn * Printexc.raw_backtrace) option;
66
on_release : (unit -> unit) Lwt_dllist.t;
7-
waiter : unit Waiters.t; (* The main [top]/[sub] function may wait here for fibers to finish. *)
7+
waiter : unit Single_waiter.t; (* The main [top]/[sub] function may wait here for fibers to finish. *)
88
cancel : Cancel.t;
99
}
1010

@@ -68,7 +68,7 @@ let dec_fibers t =
6868
if t.daemon_fibers > 0 && t.fibers = t.daemon_fibers then
6969
Cancel.cancel t.cancel Exit;
7070
if t.fibers = 0 then
71-
Waiters.wake_all t.waiter ()
71+
Single_waiter.wake t.waiter (Ok ())
7272

7373
let with_op t fn =
7474
inc_fibers t;
@@ -92,7 +92,7 @@ let rec await_idle t =
9292
(* Wait for fibers to finish: *)
9393
while t.fibers > 0 do
9494
Ctf.note_try_read t.id;
95-
Waiters.await ~mutex:None t.waiter t.id
95+
Single_waiter.await t.waiter t.id
9696
done;
9797
(* Call on_release handlers: *)
9898
let queue = Lwt_dllist.create () in
@@ -125,7 +125,7 @@ let create cancel =
125125
fibers = 1; (* The main function counts as a fiber *)
126126
daemon_fibers = 0;
127127
exs = None;
128-
waiter = Waiters.create ();
128+
waiter = Single_waiter.create ();
129129
on_release = Lwt_dllist.create ();
130130
cancel;
131131
}

0 commit comments

Comments
 (0)