Module Await.StackSource

A multi-producer, multi-consumer concurrent stack.

Sourcetype !'a t : value mod contended non_float portable

A simple, list-based multi-producer multi-consumer stack which provides both lock-free and blocking operations.

include sig ... end
Sourceval sexp_of_t : ('a : value mod contended). ('a -> Sexplib0.Sexp.t) -> 'a t -> Sexplib0.Sexp.t
Sourceval create : ?padded:Base.bool @ local -> Base.unit -> 'a t @@ portable

create () creates and returns a new empty stack.

The optional padded argument specifies whether to pad the data structure to avoid false sharing. See Atomic.make for a longer explanation.

Sourceval push : 'a t @ local -> 'a @ portable contended -> Base.unit @@ portable

push t a enqueues a at the head of t.

Sourceval pop : Await_kernel.Await.t @ local -> 'a t @ local -> 'a @ portable contended @@ portable

pop await t removes and returns the most-recently-pushed value from the head of t, blocking using await if t is empty.

Sourceval pop_or_cancel : Await_kernel.Await.t @ local -> Await_kernel.Cancellation.t @ local -> 'a t @ local -> 'a Await_kernel.Or_canceled.t @ portable contended @@ portable

pop_or_cancel await c t is Completed (pop await t) if c is not cancelled, otherwise it is Canceled.

  • raises Terminated

    if w is terminated, even if c is canceled.

Sourceval pop_nonblocking : 'a t @ local -> 'a Base.or_null @ portable contended @@ portable

pop_nonblocking t removes and returns the most-recently-pushed value from the head of t, or returns Null if the stack is empty.

Sourceval drain : 'a t @ local -> 'a Base.list @ portable contended @@ portable

drain t removes and returns all items from t without blocking, returning a list with the most-recently-enqueued item first.

Sourceval drain_blocking : Await_kernel.Await.t @ local -> 'a t @ local -> 'a Base.list @ portable contended @@ portable

drain_blocking await t removes and returns all items from t, blocking using await if t is empty. Returns a list with the most-recently-enqueued item first.

Sourceval drain_blocking_or_cancel : Await_kernel.Await.t @ local -> Await_kernel.Cancellation.t @ local -> 'a t @ local -> 'a Base.list Await_kernel.Or_canceled.t @ portable contended @@ portable

drain_blocking_or_cancel await c t is Completed (drain_blocking await t) if c is not cancelled, otherwise it is Canceled.

  • raises Terminated

    if await is terminated, even if c is canceled.

Sourcemodule For_testing : sig ... end