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.
Functions
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 toget()
a node from the queue while another thread tries toremove()
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 offalse
does not mean thatget
will yield a non-null
value!fn put(self: *Self, node: *Node) void
Appends
node
to the queue. The lifetime ofnode
must be longer than lifetim…Appends
node
to the queue. The lifetime ofnode
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 toget()
the same node at the same time.