diff --git a/src/core/task_local_storage.ml b/src/core/task_local_storage.ml index 56ff354f..28cc3be7 100644 --- a/src/core/task_local_storage.ml +++ b/src/core/task_local_storage.ml @@ -55,12 +55,15 @@ let[@inline] get_opt key = | None -> None | Some cur -> Some (get_from_ cur key) -let set (type a) ((module K) : a key) (v : a) : unit = - let cur = get_cur_ () in +let set_into_ (type a) cur ((module K) : a key) (v : a) : unit = if K.offset >= Array.length !cur then resize_ cur (K.offset + 1); !cur.(K.offset) <- K.V v; () +let[@inline] set key v : unit = + let cur = get_cur_ () in + set_into_ cur key v + let with_value key x f = let old = get key in set key x; @@ -72,7 +75,10 @@ module Private_ = struct let k_storage = k_ls_values let[@inline] create () = [||] + let[@inline] get_cur_opt () = TLS.get k_storage let copy = Array.copy + let get = get_from_ + let set = set_into_ let[@inline] copy_of_current () = copy @@ !(get_cur_ ()) let dummy = [||] end diff --git a/src/core/task_local_storage.mli b/src/core/task_local_storage.mli index 4c10155c..6ca9557e 100644 --- a/src/core/task_local_storage.mli +++ b/src/core/task_local_storage.mli @@ -51,11 +51,15 @@ val with_value : 'a key -> 'a -> (unit -> 'b) -> 'b (**/**) +(** Private API *) module Private_ : sig module Storage : sig type t = storage + val get : t ref -> 'a key -> 'a + val set : t ref -> 'a key -> 'a -> unit val k_storage : t ref option Thread_local_storage_.key + val get_cur_opt : unit -> t ref option val create : unit -> t val copy : t -> t val copy_of_current : unit -> t