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

NAME

4     ck_ring_dequeue_spmc — 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_spmc(ck_ring_t *ring, ck_ring_buffer_t *buffer,
14         void *result);
15

DESCRIPTION

17     The ck_ring_dequeue_spmc(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.  The decoupling of the ring from the buffer serves to
21     address use-cases involving multiple address spaces and DMA, among oth‐
22     ers.  If you are on non-POSIX platforms or wish for strict compliance
23     with C, then it is recommended to pass a pointer of type void ** for
24     result.  This function is safe to call without locking for UINT_MAX con‐
25     current invocations of ck_ring_dequeue_spmc(3) or
26     ck_ring_trydequeue_spmc(3) and up to one concurrent
27     ck_ring_enqueue_spmc(3) or ck_ring_tryenqueue_spmc(3) invocation. This
28     function provides lock-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_spmc(&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_spsc(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