From bdce92d5f600aeb9055479e90af2480eb0c2cb93 Mon Sep 17 00:00:00 2001 From: mefyl Date: Mon, 20 Mar 2023 20:53:49 +0100 Subject: [PATCH 1/4] Enable to read which backend was picked by libev. --- src/unix/lwt_engine.ml | 5 +++++ src/unix/lwt_engine.mli | 7 +++++++ src/unix/lwt_libev_stubs.c | 19 +++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/src/unix/lwt_engine.ml b/src/unix/lwt_engine.ml index 78fbffb6f..fbe361c32 100644 --- a/src/unix/lwt_engine.ml +++ b/src/unix/lwt_engine.ml @@ -147,6 +147,8 @@ struct let devpoll = EV_DEVPOLL let port = EV_PORT + let equal = ( = ) + let name = function | EV_DEFAULT -> "EV_DEFAULT" | EV_SELECT -> "EV_SELECT" @@ -160,6 +162,7 @@ struct end external ev_init : Ev_backend.t -> ev_loop = "lwt_libev_init" +external ev_backend : ev_loop -> Ev_backend.t = "lwt_libev_backend" external ev_stop : ev_loop -> unit = "lwt_libev_stop" external ev_loop : ev_loop -> bool -> unit = "lwt_libev_loop" external ev_unloop : ev_loop -> unit = "lwt_libev_unloop" @@ -175,6 +178,8 @@ class libev ?(backend=Ev_backend.default) () = object val loop = ev_init backend method loop = loop + method backend = ev_backend loop + method private cleanup = ev_stop loop method iter block = diff --git a/src/unix/lwt_engine.mli b/src/unix/lwt_engine.mli index 4b77908b8..f1083e0e1 100644 --- a/src/unix/lwt_engine.mli +++ b/src/unix/lwt_engine.mli @@ -127,6 +127,8 @@ sig val devpoll : t val port : t + val equal : t -> t -> bool + val pp : Format.formatter -> t -> unit end @@ -137,6 +139,9 @@ end class libev : ?backend:Ev_backend.t -> unit -> object inherit t + method backend : Ev_backend.t + (** The backend picked by libev. *) + val loop : ev_loop (** The libev loop used for this engine. *) @@ -200,6 +205,7 @@ sig class libev_1 : object inherit t val loop : ev_loop + method backend : Ev_backend.t method loop : ev_loop end [@@ocaml.deprecated @@ -214,6 +220,7 @@ sig class libev_2 : ?backend:Ev_backend.t -> unit -> object inherit t val loop : ev_loop + method backend : Ev_backend.t method loop : ev_loop end [@@ocaml.deprecated diff --git a/src/unix/lwt_libev_stubs.c b/src/unix/lwt_libev_stubs.c index 70238fe1d..cce780634 100644 --- a/src/unix/lwt_libev_stubs.c +++ b/src/unix/lwt_libev_stubs.c @@ -91,6 +91,25 @@ CAMLprim value lwt_libev_init(value backend) { return result; } +CAMLprim value lwt_libev_backend(value loop) { + switch (ev_backend(Ev_loop_val(loop))) { + case EVBACKEND_SELECT: + return Val_int(val_EVBACKEND_SELECT); + case EVBACKEND_POLL: + return Val_int(val_EVBACKEND_POLL); + case EVBACKEND_EPOLL: + return Val_int(val_EVBACKEND_EPOLL); + case EVBACKEND_KQUEUE: + return Val_int(val_EVBACKEND_KQUEUE); + case EVBACKEND_DEVPOLL: + return Val_int(val_EVBACKEND_DEVPOLL); + case EVBACKEND_PORT: + return Val_int(val_EVBACKEND_PORT); + default: + assert(0); + } +} + CAMLprim value lwt_libev_stop(value loop) { ev_loop_destroy(Ev_loop_val(loop)); return Val_unit; From 8d179bf61895df074c2dd6b166a6bfedf7598380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Proust?= Date: Mon, 3 Apr 2023 08:16:37 +0200 Subject: [PATCH 2/4] lazy-ify libev backend query to avoid initialisation error --- src/unix/lwt_engine.ml | 2 +- src/unix/lwt_engine.mli | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/unix/lwt_engine.ml b/src/unix/lwt_engine.ml index fbe361c32..ad9bd334d 100644 --- a/src/unix/lwt_engine.ml +++ b/src/unix/lwt_engine.ml @@ -178,7 +178,7 @@ class libev ?(backend=Ev_backend.default) () = object val loop = ev_init backend method loop = loop - method backend = ev_backend loop + method backend = lazy (ev_backend loop) method private cleanup = ev_stop loop diff --git a/src/unix/lwt_engine.mli b/src/unix/lwt_engine.mli index f1083e0e1..3c5ea31ee 100644 --- a/src/unix/lwt_engine.mli +++ b/src/unix/lwt_engine.mli @@ -139,7 +139,7 @@ end class libev : ?backend:Ev_backend.t -> unit -> object inherit t - method backend : Ev_backend.t + method backend : Ev_backend.t Lazy.t (** The backend picked by libev. *) val loop : ev_loop @@ -205,7 +205,7 @@ sig class libev_1 : object inherit t val loop : ev_loop - method backend : Ev_backend.t + method backend : Ev_backend.t Lazy.t method loop : ev_loop end [@@ocaml.deprecated @@ -220,7 +220,7 @@ sig class libev_2 : ?backend:Ev_backend.t -> unit -> object inherit t val loop : ev_loop - method backend : Ev_backend.t + method backend : Ev_backend.t Lazy.t method loop : ev_loop end [@@ocaml.deprecated From 213eaa79a6dd83219df087e400579b2206d2c4c9 Mon Sep 17 00:00:00 2001 From: mefyl Date: Thu, 3 Oct 2024 10:48:07 +0200 Subject: [PATCH 3/4] libev: Add unavailable stub to fix CI. --- src/unix/lwt_libev_stubs.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/unix/lwt_libev_stubs.c b/src/unix/lwt_libev_stubs.c index cce780634..ea390fa38 100644 --- a/src/unix/lwt_libev_stubs.c +++ b/src/unix/lwt_libev_stubs.c @@ -240,6 +240,7 @@ CAMLprim value lwt_libev_timer_stop(value loop, value val_watcher) { #else +LWT_NOT_AVAILABLE1(libev_backend) LWT_NOT_AVAILABLE1(libev_init) LWT_NOT_AVAILABLE1(libev_stop) LWT_NOT_AVAILABLE2(libev_loop) From d1bee236dc4ca2e2e5c35c6081057aad4d72bc0f Mon Sep 17 00:00:00 2001 From: mefyl Date: Thu, 3 Oct 2024 11:48:11 +0200 Subject: [PATCH 4/4] Revert "lazy-ify libev backend query to avoid initialisation error" This reverts commit 8d179bf61895df074c2dd6b166a6bfedf7598380. --- src/unix/lwt_engine.ml | 2 +- src/unix/lwt_engine.mli | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/unix/lwt_engine.ml b/src/unix/lwt_engine.ml index 22634712a..17618e133 100644 --- a/src/unix/lwt_engine.ml +++ b/src/unix/lwt_engine.ml @@ -180,7 +180,7 @@ class libev ?(backend=Ev_backend.default) () = object val loop = ev_init backend method loop = loop - method backend = lazy (ev_backend loop) + method backend = ev_backend loop method private cleanup = ev_stop loop diff --git a/src/unix/lwt_engine.mli b/src/unix/lwt_engine.mli index d35371557..fbdd7d199 100644 --- a/src/unix/lwt_engine.mli +++ b/src/unix/lwt_engine.mli @@ -147,7 +147,7 @@ end class libev : ?backend:Ev_backend.t -> unit -> object inherit t - method backend : Ev_backend.t Lazy.t + method backend : Ev_backend.t (** The backend picked by libev. *) val loop : ev_loop @@ -213,7 +213,7 @@ sig class libev_1 : object inherit t val loop : ev_loop - method backend : Ev_backend.t Lazy.t + method backend : Ev_backend.t method loop : ev_loop end [@@ocaml.deprecated @@ -228,7 +228,7 @@ sig class libev_2 : ?backend:Ev_backend.t -> unit -> object inherit t val loop : ev_loop - method backend : Ev_backend.t Lazy.t + method backend : Ev_backend.t method loop : ev_loop end [@@ocaml.deprecated