package picos

  1. Overview
  2. Docs

Fiber local storage

Fiber local storage is intended for use as a low overhead storage mechanism for fiber extensions. For example, one might associate a priority value with each fiber for a scheduler that uses a priority queue or one might use FLS to store unique id values for fibers.

type fiber := t

Destructively substituted alias for Fiber.t.

type 'a t

Represents a key for storing values of type 'a in storage associated with fibers.

val create : unit -> 'a t

create () allocates a new key for associating values in storage associated with fibers.

⚠️ New keys should not be created dynamically.

exception Not_set

Raised by get_exn in case value has not been set.

val get_exn : fiber -> 'a t -> 'a

get_exn fiber key returns the value associated with the key in the storage associated with the fiber or raises Not_set using raise_notrace.

⚠️ It is only safe to call get_exn from the fiber itself or when the fiber is known not to be running.

val get : fiber -> 'a t -> default:'a -> 'a

get fiber key ~default returns the value associated with the key in the storage associated with the fiber or the default value.

⚠️ It is only safe to call get from the fiber itself or when the fiber is known not to be running.

val set : fiber -> 'a t -> 'a -> unit

set fiber key value sets the value associated with the key to the given value in the storage associated with the fiber.

⚠️ It is only safe to call set from the fiber itself or when the fiber is known not to be running.

val remove : fiber -> 'a t -> unit

remove fiber key removes the value, if any, associated with the key from the storage associated with the fiber.

⚠️ It is only safe to call remove from the fiber itself or when the fiber is known not to be running.

val reserve : fiber -> 'a t -> unit

reserve fiber key ensures that sufficient space has been allocated to associate a value with the specified key such that a subsequent set with the key will not allocate.

ℹ️ This can be used to optimize the population of the FLS and to avoid performing memory allocations in critical sections.

⚠️ It is only safe to call reserve from the fiber itself or when the fiber is known not to be running.

OCaml

Innovation. Community. Security.