From 9623e2d4b66edcc029aea95a1e413005ca36895e Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Thu, 5 Sep 2024 13:24:17 -0400 Subject: [PATCH] add `Moonpool_io.main`; make `configure` idempotent --- src/io/dune | 2 +- src/io/moonpool_io.ml | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/io/dune b/src/io/dune index 8ba05ca5..cc8d0bd9 100644 --- a/src/io/dune +++ b/src/io/dune @@ -4,4 +4,4 @@ (synopsis "Async IO for moonpool, using Picos") (enabled_if (>= %{ocaml_version} 5.0)) - (libraries moonpool picos_io picos_io.select picos_io.fd)) + (libraries moonpool moonpool.fib picos_io picos_io.select picos_io.fd)) diff --git a/src/io/moonpool_io.ml b/src/io/moonpool_io.ml index 9b249347..8c1b981a 100644 --- a/src/io/moonpool_io.ml +++ b/src/io/moonpool_io.ml @@ -3,7 +3,20 @@ module Unix = Picos_io.Unix module Select = Picos_io_select let fd_of_unix_fd : Unix.file_descr -> Fd.t = Fun.id -let configure = Select.configure + +open struct + let has_configured = Atomic.make false +end + +let configure ?intr_sig ?handle_sigchld ?ignore_sigpipe () : unit = + if not (Atomic.exchange has_configured true) then + Select.configure ?intr_sig ?handle_sigchld ?ignore_sigpipe () + +(** [main f] runs [f()] inside a scheduler. *) +let main ?intr_sig ?handle_sigchld ?ignore_sigpipe (f : Moonpool.Runner.t -> 'a) + : 'a = + configure ?intr_sig ?handle_sigchld ?ignore_sigpipe (); + Moonpool_fib.main f (** {2 Async read/write} *)