Debian Codegraph @

doc/ck_ring_dequeue_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_DEQUEUE_SPMC 3
29 .Sh NAME
30 .Nm ck_ring_dequeue_spmc
31 .Nd dequeue pointer from bounded FIFO
32 .Sh LIBRARY
33 Concurrency Kit (libck, \-lck)
34 .Sh SYNOPSIS
35 .In ck_ring.h
36 .Ft bool
37 .Fn ck_ring_dequeue_spmc "ck_ring_t *ring" "ck_ring_buffer_t *buffer" "void *result"
38 .Sh DESCRIPTION
39 The
40 .Fn ck_ring_dequeue_spmc 3
41 function dequeues 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 The decoupling of the ring from the buffer serves
52 to address use-cases involving multiple address spaces
53 and DMA, among others.
54 If you are on non-POSIX platforms or wish for strict
55 compliance with C, then it is recommended to pass a
56 pointer of type void ** for
57 .Fa result .
58 This function is safe to call without locking for UINT_MAX
59 concurrent invocations of
60 .Fn ck_ring_dequeue_spmc 3
61 or
62 .Fn ck_ring_trydequeue_spmc 3
63 and up to one concurrent
64 .Fn ck_ring_enqueue_spmc 3
65 or
66 .Fn ck_ring_tryenqueue_spmc 3
67 invocation. This function provides lock-free progress
68 guarantees.
69 .Sh EXAMPLE
70 .Bd -literal -offset indent
71 #include <ck_ring.h>
72
73 /* This ring was previously initialized with ck_ring_init. */
74 ck_ring_t ring;
75
76 /* The ring was initialized for 1023 elements. */
77 ck_ring_buffer_t buffer[1024];
78
79 void
80 dequeue(void)
81 {
82 void *result;
83
84 /* Dequeue from ring until it is empty. */
85 while (ck_ring_dequeue_spmc(&ring, &buffer, &result) == true) {
86 /*
87 * Results contains the oldest pointer in ring
88 * since the dequeue operation returned true.
89 */
90 operation(result);
91 }
92
93 /* An empty ring was encountered, leave. */
94 return;
95 }
96 .Ed
97 .Sh RETURN VALUES
98 The function returns true if the buffer was non-empty.
99 The result of the dequeue operation is stored in the
100 value pointed to by
101 .Fa result .
102 The function will return false if the buffer was empty
103 and the value in
104 .Fa result
105 will be undefined.
106 .Sh SEE ALSO
107 .Xr ck_ring_init 3 ,
108 .Xr ck_ring_trydequeue_spmc 3 ,
109 .Xr ck_ring_enqueue_spmc 3 ,
110 .Xr ck_ring_enqueue_spmc_size 3 ,
111 .Xr ck_ring_dequeue_spsc 3 ,
112 .Xr ck_ring_enqueue_spsc 3 ,
113 .Xr ck_ring_enqueue_spsc_size 3 ,
114 .Xr ck_ring_capacity 3 ,
115 .Xr ck_ring_size 3
116 .Pp
117 Additional information available at http://concurrencykit.org/