more sanity checks

This commit is contained in:
Simon Cruanes 2025-09-04 15:32:32 -04:00
parent 63559f0f3b
commit 1eef212a3e
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
2 changed files with 5 additions and 2 deletions

View file

@ -34,7 +34,7 @@ module Scheduler_state = struct
tasks = Queue.create (); tasks = Queue.create ();
actions_from_other_threads = Queue.create (); actions_from_other_threads = Queue.create ();
mutex = Mutex.create (); mutex = Mutex.create ();
thread = Thread.self () |> Thread.id; thread = -1;
closed = false; closed = false;
as_runner = Moonpool.Runner.dummy; as_runner = Moonpool.Runner.dummy;
enter_hook = None; enter_hook = None;
@ -157,6 +157,8 @@ let await_lwt (fut : _ Lwt.t) =
) )
let lwt_of_fut (fut : 'a M.Fut.t) : 'a Lwt.t = let lwt_of_fut (fut : 'a M.Fut.t) : 'a Lwt.t =
if not (Ops.on_lwt_thread_ Scheduler_state.st) then
failwith "lwt_of_fut: not on the lwt thread";
let lwt_fut, lwt_prom = Lwt.wait () in let lwt_fut, lwt_prom = Lwt.wait () in
(* in lwt thread, resolve [lwt_fut] *) (* in lwt thread, resolve [lwt_fut] *)

View file

@ -18,7 +18,8 @@ val fut_of_lwt : 'a Lwt.t -> 'a Moonpool.Fut.t
val lwt_of_fut : 'a Moonpool.Fut.t -> 'a Lwt.t val lwt_of_fut : 'a Moonpool.Fut.t -> 'a Lwt.t
(** [lwt_of_fut fut] makes a lwt future that completes when [fut] does. This (** [lwt_of_fut fut] makes a lwt future that completes when [fut] does. This
must be called from the Lwt thread, and the result must always be used only must be called from the Lwt thread, and the result must always be used only
from inside the Lwt thread. *) from inside the Lwt thread.
@raise Failure if not run from the lwt thread. *)
(** {2 Helpers on the moonpool side} *) (** {2 Helpers on the moonpool side} *)