-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: optional dep on hmap, for inheritable FLS data
- Loading branch information
Showing
8 changed files
with
74 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ depends: [ | |
"mdx" {>= "1.9.0" & with-test} | ||
] | ||
depopts: [ | ||
"hmap" | ||
"trace" {>= "0.6"} | ||
] | ||
build: [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(**/**) | ||
|
||
module Private_hmap_fls_ = struct | ||
let copy_fls _ _ = () | ||
end | ||
|
||
(**/**) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
open Moonpool.Private.Types_ | ||
|
||
open struct | ||
module FLS = Picos.Fiber.FLS | ||
end | ||
|
||
(** A local hmap, inherited in children fibers *) | ||
let k_local_hmap : Hmap.t FLS.t = FLS.create () | ||
|
||
(** Access the local [hmap], or an empty one if not set *) | ||
let[@inline] get_local_hmap () : Hmap.t = | ||
let fiber = get_current_fiber_exn () in | ||
FLS.get fiber ~default:Hmap.empty k_local_hmap | ||
|
||
let[@inline] set_local_hmap (h : Hmap.t) : unit = | ||
let fiber = get_current_fiber_exn () in | ||
FLS.set fiber k_local_hmap h | ||
|
||
let[@inline] update_local_hmap (f : Hmap.t -> Hmap.t) : unit = | ||
let fiber = get_current_fiber_exn () in | ||
let h = FLS.get fiber ~default:Hmap.empty k_local_hmap in | ||
let h = f h in | ||
FLS.set fiber k_local_hmap h | ||
|
||
(** @raise Invalid_argument if not present *) | ||
let get_exn (k : 'a Hmap.key) : 'a = | ||
let h = get_local_hmap () in | ||
Hmap.get k h | ||
|
||
let get_opt (k : 'a Hmap.key) : 'a option = | ||
let h = get_local_hmap () in | ||
Hmap.find k h | ||
|
||
let[@inline] set (k : 'a Hmap.key) (v : 'a) : unit = | ||
update_local_hmap (Hmap.add k v) | ||
|
||
(**/**) | ||
|
||
module Private_hmap_fls_ = struct | ||
(** Copy the hmap from f1.fls to f2.fls *) | ||
let copy_fls (f1 : Picos.Fiber.t) (f2 : Picos.Fiber.t) : unit = | ||
match FLS.get_exn f1 k_local_hmap with | ||
| exception FLS.Not_set -> () | ||
| hmap -> FLS.set f2 k_local_hmap hmap | ||
end | ||
|
||
(**/**) |