xref: /freebsd/share/man/man9/selrecord.9 (revision 315ee00f)
1.\"
2.\" Copyright (C) 2002 Chad David <davidc@acns.ab.ca>. All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice(s), this list of conditions and the following disclaimer as
9.\"    the first lines of this file unmodified other than the possible
10.\"    addition of one or more copyright notices.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice(s), this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\"
15.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
16.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18.\" DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
19.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22.\" CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
25.\" DAMAGE.
26.\"
27.Dd August 25, 2011
28.Dt SELRECORD 9
29.Os
30.Sh NAME
31.Nm seldrain ,
32.Nm selrecord ,
33.Nm selwakeup
34.Nd "record and wakeup select requests"
35.Sh SYNOPSIS
36.In sys/param.h
37.In sys/selinfo.h
38.Ft void
39.Fn seldrain "struct selinfo *sip"
40.Ft void
41.Fn selrecord "struct thread *td" "struct selinfo *sip"
42.Ft void
43.Fn selwakeup "struct selinfo *sip"
44.Sh DESCRIPTION
45.Fn seldrain ,
46.Fn selrecord
47and
48.Fn selwakeup
49are the three central functions used by
50.Xr select 2 ,
51.Xr poll 2
52and the objects that are being selected on.
53They handle the task of recording which threads are waiting on which objects
54and the waking of the proper threads when an event of interest occurs on an
55object.
56.Pp
57.Fn selrecord
58records that the calling thread is interested in events related to a given
59object.
60If another thread is already waiting on the object a collision will be flagged
61in
62.Fa sip
63which will be later dealt with by
64.Fn selwakeup .
65.Pp
66.Fn selrecord
67acquires and releases
68.Va sellock .
69.Pp
70.Fn selwakeup
71is called by the underlying object handling code in order to notify any waiting
72threads that an event of interest has occurred.
73If a collision has occurred,
74.Fn selwakeup
75will increment
76.Va nselcoll ,
77and broadcast on the global cv in order to wake all waiting threads so that
78they can handle it.
79If the thread waiting on the object is not currently sleeping or the wait
80channel is not
81.Va selwait ,
82.Fn selwakeup
83will clear the
84.Dv TDF_SELECT
85flag which should be noted by
86.Xr select 2
87and
88.Xr poll 2
89when they wake up.
90.Pp
91.Fn seldrain
92will flush the waiters queue on a specified object before its
93destruction.
94The object handling code must ensure that
95.Fa *sip
96cannot be used once
97.Fn seldrain
98has been called.
99.Pp
100The contents of
101.Fa *sip
102must be zeroed, such as by softc initialization, before any call to
103.Fn selrecord
104or
105.Fn selwakeup ,
106otherwise a panic may occur.
107.Fn selwakeup
108acquires and releases
109.Va sellock
110and may acquire and release
111.Va sched_lock .
112.Fn seldrain
113could usually be just a wrapper for
114.Fn selwakeup ,
115but consumers should not generally rely on this feature.
116.Sh SEE ALSO
117.Xr poll 2 ,
118.Xr select 2
119.Sh AUTHORS
120.An -nosplit
121This manual page was written by
122.An Chad David Aq Mt davidc@FreeBSD.org
123and
124.An Alfred Perlstein Aq Mt alfred@FreeBSD.org .
125