Skip to content

Commit bdadd69

Browse files
committed
Lower poll_maxi when we can
We inflate maxi to account the highest index we're tracking, if we're about to unregister the highest one, find the new highest.
1 parent 9961186 commit bdadd69

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

lib_eio_posix/sched.ml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,18 @@ let update t waiters fd =
118118
in
119119
if flags = Poll.Flags.empty then (
120120
Poll.invalidate_index t.poll fdi;
121+
(* Try to find the new maxi, go back on index until we find the next
122+
used slot, -1 means none in use. *)
123+
let rec lower_maxi = function
124+
| -1 -> t.poll_maxi <- -1
125+
| index ->
126+
if Poll.((get_fd t.poll index) <> invalid_fd) then
127+
t.poll_maxi <- index
128+
else
129+
lower_maxi (pred index)
130+
in
131+
if fdi = t.poll_maxi then
132+
lower_maxi (pred fdi);
121133
Hashtbl.remove t.fd_map fd
122134
) else (
123135
Poll.set_index t.poll fdi fd flags;
@@ -223,7 +235,7 @@ let with_sched fn =
223235
in
224236
let poll = Poll.create () in
225237
let fd_map = Hashtbl.create 10 in
226-
let t = { run_q; poll; poll_maxi = 0; fd_map; eventfd; eventfd_r;
238+
let t = { run_q; poll; poll_maxi = (-1); fd_map; eventfd; eventfd_r;
227239
active_ops = 0; need_wakeup = Atomic.make false; sleep_q } in
228240
let eventfd_ri = Iomux.Util.fd_of_unix eventfd_r in
229241
Poll.set_index t.poll eventfd_ri eventfd_r Poll.Flags.pollin;

0 commit comments

Comments
 (0)