xref: /freebsd/share/man/man9/selrecord.9 (revision fa9896e082a1046ff4fbc75fcba4d18d1f2efc19)
1307ce5feSChad David.\"
2307ce5feSChad David.\" Copyright (C) 2002 Chad David <davidc@acns.ab.ca>. All rights reserved.
3307ce5feSChad David.\"
4307ce5feSChad David.\" Redistribution and use in source and binary forms, with or without
5307ce5feSChad David.\" modification, are permitted provided that the following conditions
6307ce5feSChad David.\" are met:
7307ce5feSChad David.\" 1. Redistributions of source code must retain the above copyright
8307ce5feSChad David.\"    notice(s), this list of conditions and the following disclaimer as
9307ce5feSChad David.\"    the first lines of this file unmodified other than the possible
10307ce5feSChad David.\"    addition of one or more copyright notices.
11307ce5feSChad David.\" 2. Redistributions in binary form must reproduce the above copyright
12307ce5feSChad David.\"    notice(s), this list of conditions and the following disclaimer in the
13307ce5feSChad David.\"    documentation and/or other materials provided with the distribution.
14307ce5feSChad David.\"
15307ce5feSChad David.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
16307ce5feSChad David.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17307ce5feSChad David.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18307ce5feSChad David.\" DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
19307ce5feSChad David.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20307ce5feSChad David.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21307ce5feSChad David.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22307ce5feSChad David.\" CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23307ce5feSChad David.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24307ce5feSChad David.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
25307ce5feSChad David.\" DAMAGE.
26307ce5feSChad David.\"
276aba400aSAttilio Rao.Dd August 25, 2011
28307ce5feSChad David.Dt SELRECORD 9
29307ce5feSChad David.Os
30307ce5feSChad David.Sh NAME
316aba400aSAttilio Rao.Nm seldrain ,
32307ce5feSChad David.Nm selrecord ,
3305cb5024SRuslan Ermilov.Nm selwakeup
34307ce5feSChad David.Nd "record and wakeup select requests"
35307ce5feSChad David.Sh SYNOPSIS
36307ce5feSChad David.In sys/param.h
37307ce5feSChad David.In sys/selinfo.h
38307ce5feSChad David.Ft void
396aba400aSAttilio Rao.Fn seldrain "struct selinfo *sip"
406aba400aSAttilio Rao.Ft void
41307ce5feSChad David.Fn selrecord "struct thread *td" "struct selinfo *sip"
42307ce5feSChad David.Ft void
43307ce5feSChad David.Fn selwakeup "struct selinfo *sip"
44307ce5feSChad David.Sh DESCRIPTION
456aba400aSAttilio Rao.Fn seldrain ,
46307ce5feSChad David.Fn selrecord
47307ce5feSChad Davidand
48307ce5feSChad David.Fn selwakeup
496aba400aSAttilio Raoare the three central functions used by
50307ce5feSChad David.Xr select 2 ,
51307ce5feSChad David.Xr poll 2
52307ce5feSChad Davidand the objects that are being selected on.
53307ce5feSChad DavidThey handle the task of recording which threads are waiting on which objects
54307ce5feSChad Davidand the waking of the proper threads when an event of interest occurs on an
55307ce5feSChad Davidobject.
56307ce5feSChad David.Pp
57307ce5feSChad David.Fn selrecord
58307ce5feSChad Davidrecords that the calling thread is interested in events related to a given
59307ce5feSChad Davidobject.
60307ce5feSChad DavidIf another thread is already waiting on the object a collision will be flagged
61307ce5feSChad Davidin
62307ce5feSChad David.Fa sip
63307ce5feSChad Davidwhich will be later dealt with by
64307ce5feSChad David.Fn selwakeup .
65307ce5feSChad David.Pp
66307ce5feSChad David.Fn selrecord
67307ce5feSChad Davidacquires and releases
68307ce5feSChad David.Va sellock .
69307ce5feSChad David.Pp
70307ce5feSChad David.Fn selwakeup
71307ce5feSChad Davidis called by the underlying object handling code in order to notify any waiting
72307ce5feSChad Davidthreads that an event of interest has occurred.
7305cb5024SRuslan ErmilovIf a collision has occurred,
74307ce5feSChad David.Fn selwakeup
75307ce5feSChad Davidwill increment
76307ce5feSChad David.Va nselcoll ,
77307ce5feSChad Davidand broadcast on the global cv in order to wake all waiting threads so that
78307ce5feSChad Davidthey can handle it.
79307ce5feSChad DavidIf the thread waiting on the object is not currently sleeping or the wait
80307ce5feSChad Davidchannel is not
81307ce5feSChad David.Va selwait ,
82307ce5feSChad David.Fn selwakeup
83307ce5feSChad Davidwill clear the
84307ce5feSChad David.Dv TDF_SELECT
85307ce5feSChad Davidflag which should be noted by
86307ce5feSChad David.Xr select 2
87307ce5feSChad Davidand
88307ce5feSChad David.Xr poll 2
89307ce5feSChad Davidwhen they wake up.
90307ce5feSChad David.Pp
916aba400aSAttilio Rao.Fn seldrain
926aba400aSAttilio Raowill flush the waiters queue on a specified object before its
936aba400aSAttilio Raodestruction.
946aba400aSAttilio RaoThe object handling code must ensure that
956aba400aSAttilio Rao.Fa *sip
966aba400aSAttilio Raocannot be used once
976aba400aSAttilio Rao.Fn seldrain
986aba400aSAttilio Raohas been called.
996aba400aSAttilio Rao.Pp
100dcb5531bSNate LawsonThe contents of
101dcb5531bSNate Lawson.Fa *sip
102dcb5531bSNate Lawsonmust be zeroed, such as by softc initialization, before any call to
103dcb5531bSNate Lawson.Fn selrecord
104dcb5531bSNate Lawsonor
105dcb5531bSNate Lawson.Fn selwakeup ,
106dcb5531bSNate Lawsonotherwise a panic may occur.
107307ce5feSChad David.Fn selwakeup
108307ce5feSChad Davidacquires and releases
109307ce5feSChad David.Va sellock
110307ce5feSChad Davidand may acquire and release
111307ce5feSChad David.Va sched_lock .
1126aba400aSAttilio Rao.Fn seldrain
1136aba400aSAttilio Raocould usually be just a wrapper for
1146aba400aSAttilio Rao.Fn selwakeup ,
1156aba400aSAttilio Raobut consumers should not generally rely on this feature.
116307ce5feSChad David.Sh SEE ALSO
11705cb5024SRuslan Ermilov.Xr poll 2 ,
118307ce5feSChad David.Xr select 2
119307ce5feSChad David.Sh AUTHORS
12005cb5024SRuslan Ermilov.An -nosplit
121571dba6eSHiten PandyaThis manual page was written by
122*8a7314fcSBaptiste Daroussin.An Chad David Aq Mt davidc@FreeBSD.org
123307ce5feSChad Davidand
124*8a7314fcSBaptiste Daroussin.An Alfred Perlstein Aq Mt alfred@FreeBSD.org .
125