Skip to content

Commit

Permalink
CP-32622: Delay: replace select with time_limited_read
Browse files Browse the repository at this point in the history
Signed-off-by: Edwin Török <[email protected]>
  • Loading branch information
edwintorok committed Apr 15, 2024
1 parent b093542 commit bcae6f5
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@
(odoc :with-doc)
(xapi-stdext-pervasives (= :version))
(mtime :with-test)
(xapi-stdext-unix (= :version))
)
)

Expand Down
1 change: 1 addition & 0 deletions ocaml/libs/xapi-stdext/lib/xapi-stdext-threads/dune
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
(libraries
threads.posix
unix
xapi-stdext-unix
xapi-stdext-pervasives)
)
(test
Expand Down
10 changes: 7 additions & 3 deletions ocaml/libs/xapi-stdext/lib/xapi-stdext-threads/threadext.ml
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,15 @@ module Delay = struct
pipe_out
)
in
let r, _, _ = Unix.select [pipe_out] [] [] seconds in
let open Xapi_stdext_unix.Unixext in
(* flush the single byte from the pipe *)
if r <> [] then ignore (Unix.read pipe_out (Bytes.create 1) 0 1) ;
try
let (_ : string) =
time_limited_single_read pipe_out 1 ~max_wait:seconds
in
false
with Timeout -> true
(* return true if we waited the full length of time, false if we were woken *)
r = []
with Pre_signalled -> false
)
(fun () ->
Expand Down
1 change: 1 addition & 0 deletions xapi-stdext-threads.opam
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ depends: [
"odoc" {with-doc}
"xapi-stdext-pervasives" {= version}
"mtime" {with-test}
"xapi-stdext-unix" {= version}
]
build: [
["dune" "subst"] {dev}
Expand Down

0 comments on commit bcae6f5

Please sign in to comment.