1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
<table class="head">
<tr>
<td class="head-ltitle">SELRECORD(9)</td>
<td class="head-vol">Kernel Developer's Manual</td>
<td class="head-rtitle">SELRECORD(9)</td>
</tr>
</table>
<div class="manual-text">
<section class="Sh">
<h1 class="Sh" id="NAME"><a class="permalink" href="#NAME">NAME</a></h1>
<p class="Pp"><code class="Nm">seldrain</code>,
<code class="Nm">selrecord</code>, <code class="Nm">selwakeup</code>
— <span class="Nd">record and wakeup select requests</span></p>
</section>
<section class="Sh">
<h1 class="Sh" id="SYNOPSIS"><a class="permalink" href="#SYNOPSIS">SYNOPSIS</a></h1>
<p class="Pp"><code class="In">#include
<<a class="In">sys/param.h</a>></code>
<br/>
<code class="In">#include <<a class="In">sys/selinfo.h</a>></code></p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">seldrain</code>(<var class="Fa" style="white-space: nowrap;">struct
selinfo *sip</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">selrecord</code>(<var class="Fa" style="white-space: nowrap;">struct
thread *td</var>, <var class="Fa" style="white-space: nowrap;">struct
selinfo *sip</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">selwakeup</code>(<var class="Fa" style="white-space: nowrap;">struct
selinfo *sip</var>);</p>
</section>
<section class="Sh">
<h1 class="Sh" id="DESCRIPTION"><a class="permalink" href="#DESCRIPTION">DESCRIPTION</a></h1>
<p class="Pp"><a class="permalink" href="#seldrain"><code class="Fn" id="seldrain">seldrain</code></a>(),
<code class="Fn">selrecord</code>() and <code class="Fn">selwakeup</code>()
are the three central functions used by <a class="Xr">select(2)</a>,
<a class="Xr">poll(2)</a> and the objects that are being selected on. They
handle the task of recording which threads are waiting on which objects and
the waking of the proper threads when an event of interest occurs on an
object.</p>
<p class="Pp" id="selrecord"><a class="permalink" href="#selrecord"><code class="Fn">selrecord</code></a>()
records that the calling thread is interested in events related to a given
object. If another thread is already waiting on the object a collision will
be flagged in <var class="Fa">sip</var> which will be later dealt with by
<code class="Fn">selwakeup</code>().</p>
<p class="Pp" id="selrecord~2"><a class="permalink" href="#selrecord~2"><code class="Fn">selrecord</code></a>()
acquires and releases <var class="Va">sellock</var>.</p>
<p class="Pp" id="selwakeup"><a class="permalink" href="#selwakeup"><code class="Fn">selwakeup</code></a>()
is called by the underlying object handling code in order to notify any
waiting threads that an event of interest has occurred. If a collision has
occurred, <code class="Fn">selwakeup</code>() will increment
<var class="Va">nselcoll</var>, and broadcast on the global cv in order to
wake all waiting threads so that they can handle it. If the thread waiting
on the object is not currently sleeping or the wait channel is not
<var class="Va">selwait</var>, <code class="Fn">selwakeup</code>() will
clear the <code class="Dv">TDF_SELECT</code> flag which should be noted by
<a class="Xr">select(2)</a> and <a class="Xr">poll(2)</a> when they wake
up.</p>
<p class="Pp" id="seldrain~2"><a class="permalink" href="#seldrain~2"><code class="Fn">seldrain</code></a>()
will flush the waiters queue on a specified object before its destruction.
The object handling code must ensure that <var class="Fa">*sip</var> cannot
be used once <code class="Fn">seldrain</code>() has been called.</p>
<p class="Pp" id="selrecord~3">The contents of <var class="Fa">*sip</var> must
be zeroed, such as by softc initialization, before any call to
<a class="permalink" href="#selrecord~3"><code class="Fn">selrecord</code></a>()
or <code class="Fn">selwakeup</code>(), otherwise a panic may occur.
<code class="Fn">selwakeup</code>() acquires and releases
<var class="Va">sellock</var> and may acquire and release
<var class="Va">sched_lock</var>. <code class="Fn">seldrain</code>() could
usually be just a wrapper for <code class="Fn">selwakeup</code>(), but
consumers should not generally rely on this feature.</p>
</section>
<section class="Sh">
<h1 class="Sh" id="SEE_ALSO"><a class="permalink" href="#SEE_ALSO">SEE
ALSO</a></h1>
<p class="Pp"><a class="Xr">poll(2)</a>, <a class="Xr">select(2)</a></p>
</section>
<section class="Sh">
<h1 class="Sh" id="AUTHORS"><a class="permalink" href="#AUTHORS">AUTHORS</a></h1>
<p class="Pp">This manual page was written by <span class="An">Chad David</span>
<<a class="Mt" href="mailto:davidc@FreeBSD.org">davidc@FreeBSD.org</a>>
and <span class="An">Alfred Perlstein</span>
<<a class="Mt" href="mailto:alfred@FreeBSD.org">alfred@FreeBSD.org</a>>.</p>
</section>
</div>
<table class="foot">
<tr>
<td class="foot-date">August 25, 2011</td>
<td class="foot-os">FreeBSD 15.0</td>
</tr>
</table>
|