add Moonpool_io.main; make configure idempotent

This commit is contained in:
Simon Cruanes 2024-09-05 13:24:17 -04:00
parent 65bc3c97ff
commit 9623e2d4b6
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
2 changed files with 15 additions and 2 deletions

View file

@ -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))

View file

@ -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} *)