1CK_RING_TRYDEQUEUE_SP... BSD Library Functions Manual CK_RING_TRYDEQUEUE_SP...
2

NAME

4     ck_ring_trydequeue_spmc — dequeue from bounded FIFO and allow for spuri‐
5     ous failure
6

LIBRARY

8     Concurrency Kit (libck, -lck)
9

SYNOPSIS

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

DESCRIPTION

18     The ck_ring_trydequeue_spmc(3) function attempts to dequeue a pointer
19     from the bounded buffer pointed to by ring in FIFO fashion. The pointer
20     is stored in the pointer pointed to by result.  The buffer pointed to by
21     buffer must be unique to ring and point to an array of ck_ring_buffer_t
22     of sufficient length (according to the power-of-2 elements in the buf‐
23     fer).  The decoupling of the ring from the buffer serves to address use-
24     cases involving multiple address spaces and DMA, among others.  If you
25     are on non-POSIX platforms or wish for strict compliance with C, then it
26     is recommended to pass a pointer of type void ** for result.  This func‐
27     tion is safe to call without locking for UINT_MAX concurrent
28     ck_ring_dequeue_spmc(3) or ck_ring_trydequeue_spmc(3) invocations and up
29     to one concurrent ck_ring_enqueue_spmc(3) or ck_ring_tryenqueue_spmc(3)
30     invocation. This operation will always complete in a bounded number of
31     steps. It is possible for the function to return false even if ring is
32     non-empty. This
33

EXAMPLE

35           #include <ck_ring.h>
36
37           /* This ring was previously initialized with ck_ring_init. */
38           ck_ring_t ring;
39
40           /* The ring was initialized for 1023 elements. */
41           ck_ring_buffer_t buffer[1024];
42
43           void
44           dequeue(void)
45           {
46                   void *result;
47
48                   /* Dequeue from ring until contention is actively observed. */
49                   while (ck_ring_trydequeue_spmc(&ring, &buffer, &result) == true) {
50                           /*
51                            * Results contains the oldest pointer in ring
52                            * since the dequeue operation returned true.
53                            */
54                           operation(result);
55                   }
56
57                   /* An empty ring was encountered, leave. */
58                   return;
59           }
60

RETURN VALUES

62     The function returns true if the dequeue operation completely success‐
63     fully in a bounded number of steps.  The result of the dequeue operation
64     is stored in the value pointed to by result.  Otherwise, the function
65     will return false if the buffer was empty or if the operation could not
66     be completed in a bounded number of steps. If the function returns false,
67     then the contents of result are undefined.
68

SEE ALSO

70     ck_ring_init(3), ck_ring_dequeue_spmc(3), ck_ring_enqueue_spmc(3),
71     ck_ring_enqueue_spmc_size(3), ck_ring_dequeue_spsc(3),
72     ck_ring_enqueue_spsc(3), ck_ring_enqueue_spsc_size(3),
73     ck_ring_capacity(3), ck_ring_size(3)
74
75     Additional information available at http://concurrencykit.org/
76
77                                April 20, 2013
Impressum