Debian Codegraph @

doc/ck_ring_trydequeue_spmc

raw
1 .\"
2 .\" Copyright 2012-2013 Samy Al Bahra.
3 .\" All rights reserved.
4 .\"
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
7 .\" are met:
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\" notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\" notice, this list of conditions and the following disclaimer in the
12 .\" documentation and/or other materials provided with the distribution.
13 .\"
14 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
15 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
18 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 .\" SUCH DAMAGE.
25 .\"
26 .\"
27 .Dd April 20, 2013
28 .Dt CK_RING_TRYDEQUEUE_SPMC 3
29 .Sh NAME
30 .Nm ck_ring_trydequeue_spmc
31 .Nd dequeue from bounded FIFO and allow for spurious failure
32 .Sh LIBRARY
33 Concurrency Kit (libck, \-lck)
34 .Sh SYNOPSIS
35 .In ck_ring.h
36 .Ft bool
37 .Fn ck_ring_trydequeue_spmc "ck_ring_t *ring" "ck_ring_buffer_t *buffer" "void *result"
38 .Sh DESCRIPTION
39 The
40 .Fn ck_ring_trydequeue_spmc 3
41 function attempts to dequeue a pointer from the bounded buffer
42 pointed to by
43 .Fa ring
44 in FIFO fashion. The pointer is stored in the pointer
45 pointed to by
46 .Fa result .
47 The buffer pointed to by
48 .Fa buffer
49 must be unique to
50 .Fa ring
51 and point to an array of ck_ring_buffer_t of sufficient
52 length (according to the power-of-2 elements in the buffer).
53 The decoupling of the ring from the buffer serves
54 to address use-cases involving multiple address spaces
55 and DMA, among others.
56 If you are on non-POSIX platforms or wish for strict
57 compliance with C, then it is recommended to pass a
58 pointer of type void ** for
59 .Fa result .
60 This function is safe to call without locking for UINT_MAX
61 concurrent
62 .Fn ck_ring_dequeue_spmc 3
63 or
64 .Fn ck_ring_trydequeue_spmc 3
65 invocations and up to one concurrent
66 .Fn ck_ring_enqueue_spmc 3
67 or
68 .Fn ck_ring_tryenqueue_spmc 3
69 invocation. This operation will always complete
70 in a bounded number of steps. It is
71 possible for the function to return false even
72 if
73 .Fa ring
74 is non-empty. This
75 .Sh EXAMPLE
76 .Bd -literal -offset indent
77 #include <ck_ring.h>
78
79 /* This ring was previously initialized with ck_ring_init. */
80 ck_ring_t ring;
81
82 /* The ring was initialized for 1023 elements. */
83 ck_ring_buffer_t buffer[1024];
84
85 void
86 dequeue(void)
87 {
88 void *result;
89
90 /* Dequeue from ring until contention is actively observed. */
91 while (ck_ring_trydequeue_spmc(&ring, &buffer, &result) == true) {
92 /*
93 * Results contains the oldest pointer in ring
94 * since the dequeue operation returned true.
95 */
96 operation(result);
97 }
98
99 /* An empty ring was encountered, leave. */
100 return;
101 }
102 .Ed
103 .Sh RETURN VALUES
104 The function returns true if the dequeue operation
105 completely successfully in a bounded number of steps.
106 The result of the dequeue operation is stored in the
107 value pointed to by
108 .Fa result .
109 Otherwise, the function will return false if the buffer was empty
110 or if the operation could not be completed in a bounded
111 number of steps. If the function returns false, then the contents
112 of
113 .Fa result
114 are undefined.
115 .Sh SEE ALSO
116 .Xr ck_ring_init 3 ,
117 .Xr ck_ring_dequeue_spmc 3 ,
118 .Xr ck_ring_enqueue_spmc 3 ,
119 .Xr ck_ring_enqueue_spmc_size 3 ,
120 .Xr ck_ring_dequeue_spsc 3 ,
121 .Xr ck_ring_enqueue_spsc 3 ,
122 .Xr ck_ring_enqueue_spsc_size 3 ,
123 .Xr ck_ring_capacity 3 ,
124 .Xr ck_ring_size 3
125 .Pp
126 Additional information available at http://concurrencykit.org/