fn Queue(comptime T: type) type

Many producer, many consumer, non-allocating, thread-safe. Uses a mutex to protect access. The queue does not manage ownership and the user is responsible to manage the storage of the nodes.

Parameters

T: type,

Fields

head: ?*Node,
tail: ?*Node,
mutex: std.Thread.Mutex,

Functions

fn dump(self: *Self) void

Dumps the contents of the queue to stderr.

fn dumpToStream(self: *Self, stream: anytype) !void

Dumps the contents of the queue to stream. Up to 4 elements from the head are…

Dumps the contents of the queue to stream. Up to 4 elements from the head are dumped and the tail of the queue is dumped as well.

fn get(self: *Self) ?*Node

Gets a previously inserted node or returns null if there is none. It is safe …

Gets a previously inserted node or returns null if there is none. It is safe to get() a node from the queue while another thread tries to remove() the same node at the same time.

fn init() Self

Initializes a new queue. The queue does not provide a deinit() function, so t…

Initializes a new queue. The queue does not provide a deinit() function, so the user must take care of cleaning up the queue elements.

fn isEmpty(self: *Self) bool

Returns true if the queue is currently empty. Note that in a multi-consumer e…

Returns true if the queue is currently empty. Note that in a multi-consumer environment a return value of false does not mean that get will yield a non-null value!

fn put(self: *Self, node: *Node) void

Appends node to the queue. The lifetime of node must be longer than lifetim…

Appends node to the queue. The lifetime of node must be longer than lifetime of queue.

fn remove(self: *Self, node: *Node) bool

Removes a node from the queue, returns whether node was actually removed. It is…

Removes a node from the queue, returns whether node was actually removed. It is safe to remove() a node from the queue while another thread tries to get() the same node at the same time.

fn unget(self: *Self, node: *Node) void

Prepends node to the front of the queue. The lifetime of node must be longe…

Prepends node to the front of the queue. The lifetime of node must be longer than the lifetime of the queue.

Values

Node
undefined
Self
type