package picos_aux

  1. Overview
  2. Docs
Auxiliary libraries for Picos

Install

Dune Dependency

Authors

Maintainers

Sources

picos-0.6.0.tbz
sha256=3f5a08199cf65c2dae2f7d68f3877178f1da8eabf5376e15114e5a8958087dfa
sha512=ad24910c47ce614268c4268874bb918da7f8b5f03b3ad706bbf30323635262e94ddab6be24eaebbca706bfa82c0a517d4272b396459e020c185942125c9bdb7b

doc/picos_aux.mpscq/Picos_aux_mpscq/index.html

Module Picos_aux_mpscqSource

Lock-free multi-producer, single-consumer queue.

🏎️ This data structure is optimized for use as the ready queue of a fair (i.e. FIFO) single-threaded scheduler.

API

Sourcetype !'a t

A multi-producer, single-consumer queue.

Sourceval create : ?padded:bool -> unit -> 'a t

create () returns a new empty multi-producer, single-consumer queue.

Interface for producers

ℹ️ The operations in this section can be called by both any number of producers and the single owner / consumer of the queue.

Sourceval push : 'a t -> 'a -> unit

push queue value adds the value to the tail of the queue.

Sourceval push_head : 'a t -> 'a -> unit

push_head queue value adds the value to the head of the queue.

Interface for the owner / consumer

⚠️ The operations in this section should only be called by the single owner / consumer of the queue.

Sourceexception Empty

Raised by pop_exn in case it finds the queue empty.

Sourceval pop_exn : 'a t -> 'a

pop_exn queue tries to remove the value at the head of the queue. Returns the removed value or raises Empty in case the queue was empty.

  • raises Empty

    in case the queue was empty.

Sourceval pop_all : 'a t -> 'a Seq.t

pop_all queue removes all values from the queue and returns them as a sequence.

Examples

An example top-level session:

  # let q : int Picos_aux_mpscq.t =
      Picos_aux_mpscq.create ()
  val q : int Picos_aux_mpscq.t = <abstr>

  # Picos_aux_mpscq.push q 42
  - : unit = ()

  # Picos_aux_mpscq.push_head q 76
  - : unit = ()

  # Picos_aux_mpscq.push q 101
  - : unit = ()

  # Picos_aux_mpscq.pop_exn q
  - : int = 76

  # Picos_aux_mpscq.pop_all q |> List.of_seq
  - : int list = [42; 101]
OCaml

Innovation. Community. Security.