Skip to content

Commit 3ab48ea

Browse files
committed
Remove incorrect Obj.magic
1 parent 18bd215 commit 3ab48ea

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

lib_eio_windows/sched.ml

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,24 @@ type fd_event_waiters = {
3737
write : unit Suspended.t Lwt_dllist.t;
3838
}
3939

40-
module FdMap = Map.Make (Int)
40+
module FdCompare = struct
41+
type t = Unix.file_descr
42+
let compare = Stdlib.compare
43+
end
44+
45+
module FdSet = Set.Make (FdCompare)
4146

4247
(* A structure for storing the file descriptors for select. *)
4348
type poll = {
44-
mutable to_read : Unix.file_descr FdMap.t;
45-
mutable to_write : Unix.file_descr FdMap.t;
49+
mutable to_read : FdSet.t;
50+
mutable to_write : FdSet.t;
4651
}
4752

4853
type t = {
4954
(* The queue of runnable fibers ready to be resumed. Note: other domains can also add work items here. *)
5055
run_q : runnable Lf_queue.t;
5156

5257
poll : poll;
53-
mutable poll_maxi : int; (* The highest index ever used in [poll]. *)
5458
fd_map : (Unix.file_descr, fd_event_waiters) Hashtbl.t;
5559

5660
(* When adding to [run_q] from another domain, this domain may be sleeping and so won't see the event.
@@ -114,7 +118,6 @@ let clear_event_fd t =
114118

115119
(* Update [t.poll]'s entry for [fd] to match [waiters]. *)
116120
let update t waiters fd =
117-
let fdi : int = Obj.magic fd in
118121
let flags =
119122
match not (Lwt_dllist.is_empty waiters.read),
120123
not (Lwt_dllist.is_empty waiters.write) with
@@ -125,15 +128,15 @@ let update t waiters fd =
125128
in
126129
match flags with
127130
| `Empty -> (
128-
t.poll.to_read <- FdMap.remove fdi t.poll.to_read;
129-
t.poll.to_write <- FdMap.remove fdi t.poll.to_write;
131+
t.poll.to_read <- FdSet.remove fd t.poll.to_read;
132+
t.poll.to_write <- FdSet.remove fd t.poll.to_write;
130133
Hashtbl.remove t.fd_map fd
131134
)
132-
| `R -> t.poll.to_read <- FdMap.add fdi fd t.poll.to_read
133-
| `W -> t.poll.to_write <- FdMap.add fdi fd t.poll.to_write
135+
| `R -> t.poll.to_read <- FdSet.add fd t.poll.to_read
136+
| `W -> t.poll.to_write <- FdSet.add fd t.poll.to_write
134137
| `RW ->
135-
t.poll.to_read <- FdMap.add fdi fd t.poll.to_read;
136-
t.poll.to_write <- FdMap.add fdi fd t.poll.to_write
138+
t.poll.to_read <- FdSet.add fd t.poll.to_read;
139+
t.poll.to_write <- FdSet.add fd t.poll.to_write
137140

138141
let resume t node =
139142
t.active_ops <- t.active_ops - 1;
@@ -202,9 +205,9 @@ let rec next t : [`Exit_scheduler] =
202205
If [need_wakeup] is still [true], this is fine because we don't promise to do that.
203206
If [need_wakeup = false], a wake-up event will arrive and wake us up soon. *)
204207
Ctf.(note_hiatus Wait_for_work);
205-
let cons _ fd acc = fd :: acc in
206-
let read = FdMap.fold cons t.poll.to_read [] in
207-
let write = FdMap.fold cons t.poll.to_write [] in
208+
let cons fd acc = fd :: acc in
209+
let read = FdSet.fold cons t.poll.to_read [] in
210+
let write = FdSet.fold cons t.poll.to_write [] in
208211
match Unix.select read write [] timeout with
209212
| exception Unix.(Unix_error (EINTR, _, _)) -> next t
210213
| readable, writeable, _ ->
@@ -237,14 +240,11 @@ let with_sched fn =
237240
let was_open = Rcfd.close eventfd in
238241
assert was_open
239242
in
240-
let poll = { to_read = FdMap.empty; to_write = FdMap.empty } in
243+
let poll = { to_read = FdSet.empty; to_write = FdSet.empty } in
241244
let fd_map = Hashtbl.create 10 in
242-
let t = { run_q; poll; poll_maxi = (-1); fd_map; eventfd; eventfd_r;
245+
let t = { run_q; poll; fd_map; eventfd; eventfd_r;
243246
active_ops = 0; need_wakeup = Atomic.make false; sleep_q } in
244-
let eventfd_ri : int = Obj.magic eventfd_r in
245-
t.poll.to_read <- FdMap.add eventfd_ri eventfd_r t.poll.to_read;
246-
if eventfd_ri > t.poll_maxi then
247-
t.poll_maxi <- eventfd_ri;
247+
t.poll.to_read <- FdSet.add eventfd_r t.poll.to_read;
248248
match fn t with
249249
| x -> cleanup (); x
250250
| exception ex ->

0 commit comments

Comments
 (0)