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