mirror of
https://github.com/c-cube/moonpool.git
synced 2025-12-10 21:24:05 -05:00
refactor: move optional hmap FLS stuff into core/task_local_storage
This commit is contained in:
parent
328ecf4ea5
commit
7df8c069ed
9 changed files with 20 additions and 18 deletions
|
|
@ -4,6 +4,11 @@
|
||||||
(libraries
|
(libraries
|
||||||
moonpool.private
|
moonpool.private
|
||||||
(re_export thread-local-storage)
|
(re_export thread-local-storage)
|
||||||
|
(select
|
||||||
|
hmap_ls_.ml
|
||||||
|
from
|
||||||
|
(hmap -> hmap_ls_.real.ml)
|
||||||
|
(-> hmap_ls_.dummy.ml))
|
||||||
moonpool.dpool
|
moonpool.dpool
|
||||||
(re_export exn_bt)
|
(re_export exn_bt)
|
||||||
(re_export picos))
|
(re_export picos))
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
open Moonpool.Private.Types_
|
open Types_
|
||||||
|
|
||||||
open struct
|
open struct
|
||||||
module FLS = Picos.Fiber.FLS
|
module FLS = Picos.Fiber.FLS
|
||||||
|
|
@ -36,7 +36,8 @@ let[@inline] set_in_local_hmap (k : 'a Hmap.key) (v : 'a) : unit =
|
||||||
|
|
||||||
(**/**)
|
(**/**)
|
||||||
|
|
||||||
module Private_hmap_fls_ = struct
|
(* private functions, to be used by the rest of moonpool *)
|
||||||
|
module Private_hmap_ls_ = struct
|
||||||
(** Copy the hmap from f1.fls to f2.fls *)
|
(** Copy the hmap from f1.fls to f2.fls *)
|
||||||
let copy_fls (f1 : Picos.Fiber.t) (f2 : Picos.Fiber.t) : unit =
|
let copy_fls (f1 : Picos.Fiber.t) (f2 : Picos.Fiber.t) : unit =
|
||||||
match FLS.get_exn f1 k_local_hmap with
|
match FLS.get_exn f1 k_local_hmap with
|
||||||
|
|
@ -39,3 +39,5 @@ let with_value k v (f : _ -> 'b) : 'b =
|
||||||
PF.FLS.set fiber k v;
|
PF.FLS.set fiber k v;
|
||||||
let finally () = PF.FLS.set fiber k old_v in
|
let finally () = PF.FLS.set fiber k old_v in
|
||||||
Fun.protect f ~finally
|
Fun.protect f ~finally
|
||||||
|
|
||||||
|
include Hmap_ls_
|
||||||
|
|
|
||||||
|
|
@ -36,3 +36,11 @@ val with_value : 'a t -> 'a -> (unit -> 'b) -> 'b
|
||||||
(** [with_value k v f] sets [k] to [v] for the duration of the call
|
(** [with_value k v f] sets [k] to [v] for the duration of the call
|
||||||
to [f()]. When [f()] returns (or fails), [k] is restored
|
to [f()]. When [f()] returns (or fails), [k] is restored
|
||||||
to its old value. *)
|
to its old value. *)
|
||||||
|
|
||||||
|
(** {2 Local [Hmap.t]}
|
||||||
|
|
||||||
|
This requires [hmap] to be installed. *)
|
||||||
|
|
||||||
|
include module type of struct
|
||||||
|
include Hmap_ls_
|
||||||
|
end
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,7 @@
|
||||||
(synopsis "Fibers and structured concurrency for Moonpool")
|
(synopsis "Fibers and structured concurrency for Moonpool")
|
||||||
(libraries
|
(libraries
|
||||||
moonpool
|
moonpool
|
||||||
picos
|
picos)
|
||||||
(select
|
|
||||||
hmap_fls.ml
|
|
||||||
from
|
|
||||||
(hmap -> hmap_fls.real.ml)
|
|
||||||
(-> hmap_fls.dummy.ml)))
|
|
||||||
(enabled_if
|
(enabled_if
|
||||||
(>= %{ocaml_version} 5.0))
|
(>= %{ocaml_version} 5.0))
|
||||||
(flags :standard -open Moonpool_private -open Moonpool)
|
(flags :standard -open Moonpool_private -open Moonpool)
|
||||||
|
|
|
||||||
|
|
@ -259,7 +259,7 @@ let spawn_ ~parent ~runner (f : unit -> 'a) : 'a t =
|
||||||
|
|
||||||
(* copy local hmap from parent, if present *)
|
(* copy local hmap from parent, if present *)
|
||||||
Option.iter
|
Option.iter
|
||||||
(fun (p : _ t) -> Hmap_fls.Private_hmap_fls_.copy_fls p.pfiber pfiber)
|
(fun (p : _ t) -> Fls.Private_hmap_ls_.copy_fls p.pfiber pfiber)
|
||||||
parent;
|
parent;
|
||||||
|
|
||||||
(match parent with
|
(match parent with
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1 @@
|
||||||
include Task_local_storage
|
include Task_local_storage
|
||||||
include Hmap_fls
|
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,3 @@
|
||||||
include module type of struct
|
include module type of struct
|
||||||
include Task_local_storage
|
include Task_local_storage
|
||||||
end
|
end
|
||||||
|
|
||||||
(** {2 Local [Hmap.t]}
|
|
||||||
|
|
||||||
This requires [hmap] to be installed. *)
|
|
||||||
|
|
||||||
include module type of struct
|
|
||||||
include Hmap_fls
|
|
||||||
end
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue