Skip to content

Commit

Permalink
CP-32622: Thread.wait_timed_read/wait_timed_write
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 Aug 15, 2024
1 parent 5b756b2 commit 9208739
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
20 changes: 20 additions & 0 deletions ocaml/libs/xapi-stdext/lib/xapi-stdext-threads/threadext.ml
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,23 @@ module Delay = struct
(* If the wait hasn't happened yet then store up the signal *)
)
end

let wait_timed_read fd timeout =
match Xapi_stdext_unix.Unixext.select [fd] [] [] timeout with
| [], _, _ ->
false
| [fd'], _, _ ->
assert (fd' = fd) ;
true
| _ ->
assert false

let wait_timed_write fd timeout =
match Xapi_stdext_unix.Unixext.select [] [fd] [] timeout with
| _, [], _ ->
false
| _, [fd'], _ ->
assert (fd' = fd) ;
true
| _ ->
assert false
4 changes: 4 additions & 0 deletions ocaml/libs/xapi-stdext/lib/xapi-stdext-threads/threadext.mli
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ module Delay : sig
val signal : t -> unit
(** Sends a signal to a waiting thread. See 'wait' *)
end

val wait_timed_read : Unix.file_descr -> float -> bool

val wait_timed_write : Unix.file_descr -> float -> bool

0 comments on commit 9208739

Please sign in to comment.