1 .\" $NetBSD: pcq.9,v 1.3 2010/01/08 12:12:49 rmind Exp $
3 .\" Copyright (c) 2010 The NetBSD Foundation, Inc.
4 .\" All rights reserved.
6 .\" This code is derived from software contributed to The NetBSD Foundation
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\" notice, this list of conditions and the following disclaimer in the
16 .\" documentation and/or other materials provided with the distribution.
18 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 .\" POSSIBILITY OF SUCH DAMAGE.
35 .Nd producer/consumer queue
39 .Fn pcq_create "size_t maxlen" "km_flags_t kmflags"
41 .Fn pcq_destroy "pcq_t *pcq"
43 .Fn pcq_get "pcq_t *pcq"
45 .Fn pcq_maxitems "pcq_t *pcq"
47 .Fn pcq_peek "pcq_t *pcq"
49 .Fn pcq_put "pcq_t *pcq" "void *item"
51 The machine-independent
53 interface provides lockless producer/consumer queues.
58 allows multiple writers
60 but only a single reader
62 The consumer is expected to be protected by a lock that covers
63 the structure that the
67 e.g., socket lock, ifnet hwlock
69 These queues operate in a first-in, first-out
72 The act of inserting or removing an item from a
74 does not modify the item in any way.
76 does not prevent an item from being inserted multiple times into a single
79 .Bl -tag -width compact
80 .It Fn pcq_create "maxlen" "kmflags"
81 Create a queue that can store at most
89 is allowed to sleep until resources are available, or
93 immediately, if resources are unavailable.
94 .It Fn pcq_destroy "pcq"
95 Free the resources held by
98 Remove the next item to be consumed from the queue and return
100 If the queue is empty,
103 .It Fn pcq_maxitems "pcq"
104 Return the maximum number of items that the queue can store at
106 .It Fn pcq_peek "pcq"
107 Return the next item to be consumed from the queue but do not remove
109 If the queue is empty,
112 .It Fn pcq_put "pcq" "item"
113 Place an item at the end of the queue.
114 If there is no room in the queue for the item, return
118 The item must not have the value of
122 This section describes places within the
124 source tree where actual code implementing the
128 All pathnames are relative to
133 interface is implemented within the file
134 .Pa sys/kern/subr_pcq.c .
142 interface first appeared in
145 .An Matt Thomas Aq matt@NetBSD.org
148 .\" .Sh SECURITY CONSIDERATIONS