package moonpool

  1. Overview
  2. Docs
Pools of threads supported by a pool of domains

Install

dune-project
 Dependency

Authors

Maintainers

Sources

moonpool-0.10.tbz
sha256=6e3ddd37c8db9b2b7945031a72f716ba291753b1b212dd85af3cc1d62325375a
sha512=07e51249842078b08850506ff76800c4fc9185113a08b69c517fd3e6e561120dbd12a0aabd89518a540adf4d0711fd0785894595d2a3e39a799e764a427c25fc

doc/src/moonpool/types_.ml.html

Source file types_.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
module TLS = Thread_local_storage
module Domain_pool_ = Moonpool_dpool

type task = unit -> unit
type fiber = Picos.Fiber.t

type runner = {
  run_async: fiber:fiber -> task -> unit;
  shutdown: wait:bool -> unit -> unit;
  size: unit -> int;
  num_tasks: unit -> int;
}

let k_cur_runner : runner TLS.t = TLS.create ()
let k_cur_fiber : fiber TLS.t = TLS.create ()

let _dummy_computation : Picos.Computation.packed =
  let c = Picos.Computation.create () in
  Picos.Computation.cancel c (Failure "dummy fiber") (Printexc.get_callstack 0);
  Picos.Computation.Packed c

let _dummy_fiber = Picos.Fiber.create_packed ~forbid:true _dummy_computation
let[@inline] get_current_runner () : _ option = TLS.get_opt k_cur_runner

let[@inline] get_current_fiber () : fiber option =
  match TLS.get_exn k_cur_fiber with
  | f when f != _dummy_fiber -> Some f
  | _ -> None
  | exception TLS.Not_set -> None

let error_get_current_fiber_ =
  "Moonpool: get_current_fiber was called outside of a fiber."

let[@inline] get_current_fiber_exn () : fiber =
  match TLS.get_exn k_cur_fiber with
  | f when f != _dummy_fiber -> f
  | _ -> failwith error_get_current_fiber_
  | exception TLS.Not_set -> failwith error_get_current_fiber_