1CK_RING_DEQUEUE_SPSC(3)  BSD Library Functions Manual  CK_RING_DEQUEUE_SPSC(3)
2

NAME

4     ck_ring_dequeue_spsc — dequeue pointer from bounded FIFO
5

LIBRARY

7     Concurrency Kit (libck, -lck)
8

SYNOPSIS

10     #include <ck_ring.h>
11
12     bool
13     ck_ring_dequeue_spsc(ck_ring_t *ring, ck_ring_buffer_t *buffer,
14         void *result);
15

DESCRIPTION

17     The ck_ring_dequeue_spsc(3) function dequeues a pointer from the bounded
18     buffer pointed to by ring in FIFO fashion. The pointer is stored in the
19     pointer pointed to by result.  The buffer pointed to by buffer must be
20     unique to ring and point to an array of ck_ring_buffer_t of sufficient
21     length (according to the power-of-2 elements in the buffer).  The decou‐
22     pling of the ring from the buffer serves to address use-cases involving
23     multiple address spaces and DMA, among others.  If you are on non-POSIX
24     platforms or wish for strict compliance with C, then it is recommended to
25     pass a pointer of type void ** for result.  This function is safe to call
26     without locking for one concurrent invocation of ck_ring_dequeue_spsc(3)
27     and up to one concurrent ck_ring_enqueue_spsc(3) invocation. This func‐
28     tion provides wait-free progress guarantees.
29

EXAMPLE

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           dequeue(void)
41           {
42                   void *result;
43
44                   /* Dequeue from ring until it is empty. */
45                   while (ck_ring_dequeue_spsc(&ring, &buffer, &result) == true) {
46                           /*
47                            * Results contains the oldest pointer in ring
48                            * since the dequeue operation returned true.
49                            */
50                           operation(result);
51                   }
52
53                   /* An empty ring was encountered, leave. */
54                   return;
55           }
56

RETURN VALUES

58     The function returns true if the buffer was non-empty.  The result of the
59     dequeue operation is stored in the value pointed to by result.  The func‐
60     tion will return false if the buffer was empty and the value in result
61     will be undefined.
62

SEE ALSO

64     ck_ring_init(3), ck_ring_trydequeue_spmc(3), ck_ring_enqueue_spmc(3),
65     ck_ring_enqueue_spmc_size(3), ck_ring_dequeue_spmc(3),
66     ck_ring_enqueue_spsc(3), ck_ring_enqueue_spsc_size(3),
67     ck_ring_capacity(3), ck_ring_size(3)
68
69     Additional information available at http://concurrencykit.org/
70
71                                April 20, 2013
Impressum