CK_RING_DEQUEUE_SPSC(3)
π ck_ring_dequeue_spsc β dequeue pointer from bounded FIFO π
okay bestie, welcome to the ck_ring_dequeue_spsc(3) page, straight outta the Concurrency Kit manual, and yes it lives in libck so you're gonna want -lck when you link. let's get into it π«Ά
β¨ NAME β¨
ck_ring_dequeue_spsc β dequeue a pointer from a bounded FIFO, no cap π
π LIBRARY π
Concurrency Kit β link it with -lck and you're golden π
πΈ SYNOPSIS πΈ
#include <ck_ring.h>
bool
ck_ring_dequeue_spsc(ck_ring_t *ring, ck_ring_buffer_t *buffer,
void *result);
π¦ DESCRIPTION π¦
so like, the ck_ring_dequeue_spsc(3) function pulls a pointer OUT of the bounded buffer that ring points to, and it does it FIFO style β first in, first out, the way the universe intended. that pointer gets stored in the thing that result points to. iconic.
the buffer that buffer points to has to be unique to ring, bestie, no sharing, and it must point to an array of ck_ring_buffer_t that's long enough β and "long enough" means according to the power-of-2 number of elements in the buffer. math is math. π
now here's the serve: the ring and the buffer being decoupled from each other? that's on purpose. it exists to handle use-cases involving multiple address spaces and DMA, among other things. very demure, very mindful, very flexible.
if you're on non-POSIX platforms or you just want strict compliance with C, then the recommendation is to pass a pointer of type void ** for result. noted. βοΈ
and the safety tea: this function is safe to call without locking for one concurrent invocation of ck_ring_dequeue_spsc(3) and up to one concurrent ck_ring_enqueue_spsc(3) invocation. that's the SPSC deal β single producer, single consumer, and that's the whole vibe. also it provides wait-free progress guarantees, which is lowkey the slay of the century. π₯
π EXAMPLE π
#include <ck_ring.h>
/* This ring was previously initialized with ck_ring_init. */
ck_ring_t ring;
/* The ring was initialized for 1023 elements. */
ck_ring_buffer_t buffer[1024];
void
dequeue(void)
{
void *result;
/* Dequeue from ring until it is empty. */
while (ck_ring_dequeue_spsc(&ring, &buffer, &result) == true) {
/*
* Results contains the oldest pointer in ring
* since the dequeue operation returned true.
*/
operation(result);
}
/* An empty ring was encountered, leave. */
return;
}
see how the while loop just keeps going until it gets false? that's the whole loop-until-empty moment. she's eating and leaving no crumbs π
β RETURN VALUES β
- returns
trueif the buffer was non-empty π and the result of the dequeue operation is stored in the value thatresultpoints to. - returns
falseif the buffer was empty, and ngl, in that case the value inresultis undefined. like, do not read it. don't do it. π
π SEE ALSO π
ck_ring_init(3)ck_ring_trydequeue_spmc(3)ck_ring_enqueue_spmc(3)ck_ring_enqueue_spmc_size(3)ck_ring_dequeue_spmc(3)ck_ring_enqueue_spsc(3)ck_ring_enqueue_spsc_size(3)ck_ring_capacity(3)ck_ring_size(3)
more info, as always, at http://concurrencykit.org/ πβ¨
fr fr, remember:bufferisring's exclusive bestie,resultgets the pointer, and empty meansfalsewith an undefinedresult. iykyk π§
and that's the page, angel π this was CK_RING_DEQUEUE_SPSC(3) from April 20, 2013 β mwah, go dequeue something iconic πβ¨
π¦ where this page comes from
- alpine 3.24: ck-doc 0.7.2-r1 Β· BSD-2-Clause AND Apache-2.0
- debian bookworm: libck-dev 0.7.1-10 Β· BSD-2-Clause
- debian trixie: libck-dev 0.7.2-6 Β· BSD-2-Clause
- epel 10: ck-devel 0.7.2-1.el10_1 Β· BSD-2-clause AND Apache-2.0 AND BSD-3-clause
- epel 9: ck-devel 0.7.0-10.el9 Β· BSD
- fedora 43: ck-devel 0.7.2-2.fc43 Β· BSD-2-clause AND Apache-2.0 AND BSD-3-clause
- fedora 43: ck-devel 0.7.2-2.fc43 Β· BSD-2-clause AND Apache-2.0 AND BSD-3-clause
- fedora 44: ck-devel 0.7.2-4.fc44 Β· BSD-2-clause AND Apache-2.0 AND BSD-3-clause
- fedora 44: ck-devel 0.7.2-4.fc44 Β· BSD-2-clause AND Apache-2.0 AND BSD-3-clause
- nixos 26.05: ck 0.7.2
- nixpkgs unstable: ck 0.7.2
- opensuse-leap 16.0: ck-devel 0.7.2-bp160.1.9 Β· Apache-2.0 AND BSD-2-Clause
- opensuse-leap 16.0: ck-devel 0.7.2-bp160.1.9 Β· Apache-2.0 AND BSD-2-Clause
- opensuse-leap 16.0: ck-devel 0.7.2-bp160.1.9 Β· Apache-2.0 AND BSD-2-Clause
- ubuntu jammy: libck-dev 0.7.1-6ubuntu2 Β· BSD-2-Clause
- ubuntu noble: libck-dev 0.7.1-13build1 Β· BSD-2-Clause
- ubuntu questing: libck-dev 0.7.2-5ubuntu1
- ubuntu resolute: libck-dev 0.7.2-5ubuntu2 Β· BSD-2-Clause
- ubuntu stonking: libck-dev 0.7.2-11 Β· BSD-2-Clause
- Copyright 2012-2013 Samy Al Bahra
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms