[BACK]Return to pcq.9 CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / share / man / man9

File: [cvs.NetBSD.org] / src / share / man / man9 / pcq.9 (download)

Revision 1.7, Sat Apr 18 08:04:58 2015 UTC (9 years ago) by mlelstv
Branch: MAIN
CVS Tags: prg-localcount2-base3, prg-localcount2-base2, prg-localcount2-base1, prg-localcount2-base, prg-localcount2, pgoyette-localcount-base, pgoyette-localcount-20170426, pgoyette-localcount-20170320, pgoyette-localcount-20170107, pgoyette-localcount-20161104, pgoyette-localcount-20160806, pgoyette-localcount-20160726, pgoyette-localcount, perseant-stdc-iso10646-base, perseant-stdc-iso10646, netbsd-8-base, netbsd-8-2-RELEASE, netbsd-8-1-RELEASE, netbsd-8-1-RC1, netbsd-8-0-RELEASE, netbsd-8-0-RC2, netbsd-8-0-RC1, netbsd-8, matt-nb8-mediatek-base, matt-nb8-mediatek, localcount-20160914, bouyer-socketcan-base1, bouyer-socketcan-base, bouyer-socketcan
Changes since 1.6: +2 -2 lines

fix reference to queue(3)

.\"     $NetBSD: pcq.9,v 1.7 2015/04/18 08:04:58 mlelstv Exp $
.\"
.\" Copyright (c) 2010 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to The NetBSD Foundation
.\" by Matt Thomas.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd January 22, 2012
.Dt PCQ 9
.Os
.Sh NAME
.Nm pcq
.Nd producer/consumer queue
.Sh SYNOPSIS
.In sys/pcq.h
.Ft pcq_t *
.Fn pcq_create "size_t maxlen" "km_flags_t kmflags"
.Ft void
.Fn pcq_destroy "pcq_t *pcq"
.Ft void *
.Fn pcq_get "pcq_t *pcq"
.Ft size_t
.Fn pcq_maxitems "pcq_t *pcq"
.Ft void *
.Fn pcq_peek "pcq_t *pcq"
.Ft bool
.Fn pcq_put "pcq_t *pcq" "void *item"
.Sh DESCRIPTION
The machine-independent
.Nm
interface provides lockless producer/consumer queues.
A queue
.Po
.Vt pcq_t
.Pc
allows multiple writers
.Pq producers ,
but only a single reader
.Pq consumer .
The consumer is expected to be protected by a lock that covers
the structure that the
.Vt pcq_t
is embedded into
.Po
e.g., socket lock, ifnet hwlock
.Pc .
These queues operate in a first-in, first-out
.Pq FIFO
manner.
The act of inserting or removing an item from a
.Vt pcq_t
does not modify the item in any way.
.Nm
does not prevent an item from being inserted multiple times into a single
.Vt pcq_t .
.Sh FUNCTIONS
.Bl -tag -width compact
.It Fn pcq_create "maxlen" "kmflags"
Create a queue that can store at most
.Fa maxlen
items at one time.
.Fa kmflags
should be either
.Dv KM_SLEEP ,
if
.Fn pcq_create
is allowed to sleep until resources are available, or
.Dv KM_NOSLEEP
if it should return
.Dv NULL
immediately, if resources are unavailable.
.It Fn pcq_destroy "pcq"
Free the resources held by
.Fa pcq .
.It Fn pcq_get "pcq"
Remove the next item to be consumed from the queue and return it.
If the queue is empty,
return
.Dv NULL .
The caller must prevent concurrent gets from occuring.
.It Fn pcq_maxitems "pcq"
Return the maximum number of items that the queue can store at
any one time.
.It Fn pcq_peek "pcq"
Return the next item to be consumed from the queue but do not remove
it from the queue.
If the queue is empty,
return
.Dv NULL .
.It Fn pcq_put "pcq" "item"
Place an item at the end of the queue.
If there is no room in the queue for the item, return
.Dv false ;
otherwise, return
.Dv true .
The item must not have the value of
.Dv NULL .
.El
.Sh CODE REFERENCES
The
.Nm
interface is implemented within the file
.Pa sys/kern/subr_pcq.c .
.\" .Sh EXAMPLES
.Sh SEE ALSO
.Xr atomic_ops 3 ,
.Xr queue 3
.Sh HISTORY
The
.Nm
interface first appeared in
.Nx 6.0 .
.\" .Sh CAVEATS
.\" .Sh BUGS
.\" .Sh SECURITY CONSIDERATIONS