From 41805ba1a2880003d3abe5fa3e59bcb40c377b88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= Date: Tue, 21 Nov 2023 15:39:40 +0000 Subject: [PATCH] CP-32622: Delay: replace select with time_limited_read MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Edwin Török --- dune-project | 1 + ocaml/libs/xapi-stdext/lib/xapi-stdext-threads/dune | 1 + .../xapi-stdext/lib/xapi-stdext-threads/threadext.ml | 10 +++++++--- xapi-stdext-threads.opam | 1 + 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/dune-project b/dune-project index b412b0bfa94..1ae4affa93c 100644 --- a/dune-project +++ b/dune-project @@ -338,6 +338,7 @@ (odoc :with-doc) (xapi-stdext-pervasives (= :version)) (mtime :with-test) + (xapi-stdext-unix (= :version)) ) ) diff --git a/ocaml/libs/xapi-stdext/lib/xapi-stdext-threads/dune b/ocaml/libs/xapi-stdext/lib/xapi-stdext-threads/dune index a3b4d9f8609..4db49ea52e2 100644 --- a/ocaml/libs/xapi-stdext/lib/xapi-stdext-threads/dune +++ b/ocaml/libs/xapi-stdext/lib/xapi-stdext-threads/dune @@ -5,6 +5,7 @@ (libraries threads.posix unix + xapi-stdext-unix xapi-stdext-pervasives) ) (test diff --git a/ocaml/libs/xapi-stdext/lib/xapi-stdext-threads/threadext.ml b/ocaml/libs/xapi-stdext/lib/xapi-stdext-threads/threadext.ml index 56025d51154..ef30cfb5ba4 100644 --- a/ocaml/libs/xapi-stdext/lib/xapi-stdext-threads/threadext.ml +++ b/ocaml/libs/xapi-stdext/lib/xapi-stdext-threads/threadext.ml @@ -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 () -> diff --git a/xapi-stdext-threads.opam b/xapi-stdext-threads.opam index e6ad1798938..8de2f45c03e 100644 --- a/xapi-stdext-threads.opam +++ b/xapi-stdext-threads.opam @@ -14,6 +14,7 @@ depends: [ "odoc" {with-doc} "xapi-stdext-pervasives" {= version} "mtime" {with-test} + "xapi-stdext-unix" {= version} ] build: [ ["dune" "subst"] {dev}