1CK_RING_ENQUEUE_SPSC(3) BSD Library Functions Manual CK_RING_ENQUEUE_SPSC(3)
2
4 ck_ring_enqueue_spsc — enqueue pointer into bounded FIFO
5
7 Concurrency Kit (libck, -lck)
8
10 #include <ck_ring.h>
11
12 bool
13 ck_ring_enqueue_spsc(ck_ring_t *ring, ck_ring_buffer_t *buffer,
14 void *entry);
15
17 The ck_ring_enqueue_spsc(3) function enqueues the pointer entry into the
18 bounded buffer pointed to by ring in FIFO fashion. The buffer pointed to
19 by buffer must be unique to ring and point to an array of ck_ring_buf‐
20 fer_t of sufficient length (according to the power-of-2 elements in the
21 buffer). The decoupling of the ring from the buffer serves to address
22 use-cases involving multiple address spaces and DMA, among others. If
23 you are on non-POSIX platforms or wish for strict compliance with C, then
24 it is recommended to pass a pointer of type void ** for entry. This
25 function is safe to call without locking for up to one concurrent invoca‐
26 tion of ck_ring_dequeue_spsc(3). This function provides wait-free
27 progress guarantees.
28
30 #include <ck_ring.h>
31
32 /* This ring was previously initialized with ck_ring_init. */
33 ck_ring_t ring;
34
35 /* The ring was initialized for 1023 elements. */
36 ck_ring_buffer_t buffer[1024];
37
38 void
39 enqueue(void)
40 {
41 void *entry = some_object;
42
43 /* Attempt to enqueue pointer to some_object into buffer. */
44 if (ck_ring_enqueue_spsc(&ring, &buffer, &entry) == false) {
45 /*
46 * The buffer was full and the enqueue operation
47 * has failed.
48 */
49 return;
50 }
51
52 /* Enqueue operation completed successfully. */
53 return;
54 }
55
57 The function returns true if the value of entry was successfully enqueued
58 into ring. The function will return false if the value of entry could
59 not be enqueued which only occurs if ring was full.
60
62 ck_ring_init(3), ck_ring_dequeue_spmc(3), ck_ring_trydequeue_spmc(3),
63 ck_ring_enqueue_spmc(3), ck_ring_enqueue_spmc_size(3),
64 ck_ring_dequeue_spsc(3), ck_ring_enqueue_spsc_size(3),
65 ck_ring_capacity(3), ck_ring_size(3)
66
67 Additional information available at http://concurrencykit.org/
68
69 April 20, 2013