Debian Codegraph @

doc/ck_ring_enqueue_spsc

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_ENQUEUE_SPSC 3
29 .Sh NAME
30 .Nm ck_ring_enqueue_spsc
31 .Nd enqueue pointer into 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_enqueue_spsc "ck_ring_t *ring" "ck_ring_buffer_t *buffer" "void *entry"
38 .Sh DESCRIPTION
39 The
40 .Fn ck_ring_enqueue_spsc 3
41 function enqueues the pointer
42 .Fa entry
43 into the bounded buffer pointed to by
44 .Fa ring
45 in FIFO fashion.
46 The buffer pointed to by
47 .Fa buffer
48 must be unique to
49 .Fa ring
50 and point to an array of ck_ring_buffer_t of sufficient
51 length (according to the power-of-2 elements in the buffer).
52 The decoupling of the ring from the buffer serves
53 to address use-cases involving multiple address spaces
54 and DMA, among others.
55 If you are on non-POSIX platforms or wish for strict
56 compliance with C, then it is recommended to pass a
57 pointer of type void ** for
58 .Fa entry .
59 This function is safe to call without locking for up to
60 one concurrent invocation of
61 .Fn ck_ring_dequeue_spsc 3 .
62 This function provides wait-free progress
63 guarantees.
64 .Sh EXAMPLE
65 .Bd -literal -offset indent
66 #include <ck_ring.h>
67
68 /* This ring was previously initialized with ck_ring_init. */
69 ck_ring_t ring;
70
71 /* The ring was initialized for 1023 elements. */
72 ck_ring_buffer_t buffer[1024];
73
74 void
75 enqueue(void)
76 {
77 void *entry = some_object;
78
79 /* Attempt to enqueue pointer to some_object into buffer. */
80 if (ck_ring_enqueue_spsc(&ring, &buffer, &entry) == false) {
81 /*
82 * The buffer was full and the enqueue operation
83 * has failed.
84 */
85 return;
86 }
87
88 /* Enqueue operation completed successfully. */
89 return;
90 }
91 .Ed
92 .Sh RETURN VALUES
93 The function returns true if the value of
94 .Fa entry
95 was successfully enqueued into
96 .Fa ring .
97 The function will return false if the value of
98 .Fa entry
99 could not be enqueued which only occurs if
100 .Fa ring
101 was full.
102 .Sh SEE ALSO
103 .Xr ck_ring_init 3 ,
104 .Xr ck_ring_dequeue_spmc 3 ,
105 .Xr ck_ring_trydequeue_spmc 3 ,
106 .Xr ck_ring_enqueue_spmc 3 ,
107 .Xr ck_ring_enqueue_spmc_size 3 ,
108 .Xr ck_ring_dequeue_spsc 3 ,
109 .Xr ck_ring_enqueue_spsc_size 3 ,
110 .Xr ck_ring_capacity 3 ,
111 .Xr ck_ring_size 3
112 .Pp
113 Additional information available at http://concurrencykit.org/