Skip to content

Commit b411adc

Browse files
authored
Merge pull request #5861 from edwintorok/private/edvint/epoll4.0-delay
[epoll]: replace duplicate Delay modules with ThreadExt.Delay
2 parents 54abab8 + d9590a0 commit b411adc

File tree

4 files changed

+4
-92
lines changed

4 files changed

+4
-92
lines changed

message-switch-unix.opam

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ depends: [
1919
"base-threads"
2020
"message-switch-core"
2121
"ppx_deriving_rpc"
22+
"xapi-stdext-unix"
2223
]
2324
synopsis: "A simple store-and-forward message switch"
2425
description: """

ocaml/message-switch/unix/dune

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
rpclib.core
1212
rpclib.json
1313
threads.posix
14+
xapi-stdext-threads
1415
)
1516
(preprocess (pps ppx_deriving_rpc))
1617
)

ocaml/message-switch/unix/protocol_unix_scheduler.ml

Lines changed: 1 addition & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -34,71 +34,7 @@ module Int64Map = Map.Make (struct
3434
let compare = compare
3535
end)
3636

37-
module Delay = struct
38-
(* Concrete type is the ends of a pipe *)
39-
type t = {
40-
(* A pipe is used to wake up a thread blocked in wait: *)
41-
mutable pipe_out: Unix.file_descr option
42-
; mutable pipe_in: Unix.file_descr option
43-
; (* Indicates that a signal arrived before a wait: *)
44-
mutable signalled: bool
45-
; m: Mutex.t
46-
}
47-
48-
let make () =
49-
{pipe_out= None; pipe_in= None; signalled= false; m= Mutex.create ()}
50-
51-
exception Pre_signalled
52-
53-
let wait (x : t) (seconds : float) =
54-
let to_close = ref [] in
55-
let close' fd =
56-
if List.mem fd !to_close then Unix.close fd ;
57-
to_close := List.filter (fun x -> fd <> x) !to_close
58-
in
59-
finally'
60-
(fun () ->
61-
try
62-
let pipe_out =
63-
Mutex.execute x.m (fun () ->
64-
if x.signalled then (
65-
x.signalled <- false ;
66-
raise Pre_signalled
67-
) ;
68-
let pipe_out, pipe_in = Unix.pipe () in
69-
(* these will be unconditionally closed on exit *)
70-
to_close := [pipe_out; pipe_in] ;
71-
x.pipe_out <- Some pipe_out ;
72-
x.pipe_in <- Some pipe_in ;
73-
x.signalled <- false ;
74-
pipe_out
75-
)
76-
in
77-
let r, _, _ = Unix.select [pipe_out] [] [] seconds in
78-
(* flush the single byte from the pipe *)
79-
if r <> [] then ignore (Unix.read pipe_out (Bytes.create 1) 0 1) ;
80-
(* return true if we waited the full length of time, false if we were woken *)
81-
r = []
82-
with Pre_signalled -> false
83-
)
84-
(fun () ->
85-
Mutex.execute x.m (fun () ->
86-
x.pipe_out <- None ;
87-
x.pipe_in <- None ;
88-
List.iter close' !to_close
89-
)
90-
)
91-
92-
let signal (x : t) =
93-
Mutex.execute x.m (fun () ->
94-
match x.pipe_in with
95-
| Some fd ->
96-
ignore (Unix.write fd (Bytes.of_string "X") 0 1)
97-
| None ->
98-
x.signalled <- true
99-
(* If the wait hasn't happened yet then store up the signal *)
100-
)
101-
end
37+
module Delay = Xapi_stdext_threads.Threadext.Delay
10238

10339
type item = {id: int; name: string; fn: unit -> unit}
10440

ocaml/xapi-idl/lib/scheduler.ml

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,7 @@ open D
1818

1919
let with_lock = Xapi_stdext_threads.Threadext.Mutex.execute
2020

21-
module PipeDelay = struct
22-
(* Concrete type is the ends of a pipe *)
23-
type t = {
24-
(* A pipe is used to wake up a thread blocked in wait: *)
25-
pipe_out: Unix.file_descr
26-
; pipe_in: Unix.file_descr
27-
}
28-
29-
let make () =
30-
let pipe_out, pipe_in = Unix.pipe () in
31-
{pipe_out; pipe_in}
32-
33-
let wait (x : t) (seconds : float) =
34-
let timeout = if seconds < 0.0 then 0.0 else seconds in
35-
if Thread.wait_timed_read x.pipe_out timeout then
36-
(* flush the single byte from the pipe *)
37-
let (_ : int) = Unix.read x.pipe_out (Bytes.create 1) 0 1 in
38-
(* return false if we were woken *)
39-
false
40-
else
41-
(* return true if we waited the full length of time, false if we were woken *)
42-
true
43-
44-
let signal (x : t) =
45-
let (_ : int) = Unix.write x.pipe_in (Bytes.of_string "X") 0 1 in
46-
()
47-
end
21+
module PipeDelay = Xapi_stdext_threads.Threadext.Delay
4822

4923
type handle = Mtime.span * int
5024

0 commit comments

Comments
 (0)