CK_RING_ENQUEUE_SPSC(3)

✨ CK_RING_ENQUEUE_SPSC(3) ✨

okay bestie, welcome to the CK_RING_ENQUEUE_SPSC(3) page πŸ’– this is the Concurrency Kit girlies' guide to yeeting a pointer into a bounded FIFO, and honestly? it's giving main character energy. let's get into it 🫢


🌸 NAME 🌸

ck_ring_enqueue_spsc β€” enqueue pointer into bounded FIFO πŸŽ€


πŸ’œ LIBRARY πŸ’œ

Concurrency Kit (that's libck, and you link it with -lck, iykyk) πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <ck_ring.h>

bool
ck_ring_enqueue_spsc(ck_ring_t *ring, ck_ring_buffer_t *buffer,
    void *entry);

✨ DESCRIPTION ✨

so like, the ck_ring_enqueue_spsc(3) function enqueues the pointer entry into the bounded buffer pointed to by ring, and it does it in FIFO fashion β€” first in, first out, no cutting the line bestie πŸŽ€

the buffer pointed to by buffer must be unique to ring and must point to an array of ck_ring_buffer_t of sufficient length (that length is according to the power-of-2 elements in the buffer). no cap, that part is important πŸ‘‘

the whole decoupling-the-ring-from-the-buffer situation? it's not just for the aesthetic ✨ it serves to address use-cases involving multiple address spaces and DMA, among others. iconic design choice, honestly.

if you're on non-POSIX platforms, or you just wish for strict compliance with C, then it is recommended that you pass a pointer of type void ** for entry. 🌈

this function is safe to call without locking for up to one concurrent invocation of ck_ring_dequeue_spsc(3). and the best part? this function provides wait-free progress guarantees 🧚 periodt.


πŸ’– EXAMPLE πŸ’–

here's the vibe, copy it exactly bestie:

#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
enqueue(void)
{
        void *entry = some_object;

        /* Attempt to enqueue pointer to some_object into buffer. */
        if (ck_ring_enqueue_spsc(&ring, &buffer, &entry) == false) {
                /*
                 * The buffer was full and the enqueue operation
                 * has failed.
                 */
                return;
        }

        /* Enqueue operation completed successfully. */
        return;
}

πŸ”₯ RETURN VALUES πŸ”₯

  • the function returns true if the value of entry was successfully enqueued into ring. slay πŸ’…
  • the function returns false if the value of entry could not be enqueued β€” and that only happens if ring was full. so if you got a false, your ring was packed, no room, sorry babe 😭

🌈 SEE ALSO 🌈

additional information is available at http://concurrencykit.org/ β€” go read it, bestie, it's worth it πŸ’œ


okay that's the whole page!! πŸŽ€ this was CK_RING_ENQUEUE_SPSC(3) from Concurrency Kit, dated April 20, 2013 β€” literally a classic, an icon, a legend, and she still ate πŸ’…βœ¨ bye bestie, go enqueue something πŸ¦‹

πŸ“¦ where this page comes from