xref: /netbsd-src/lib/libc/sys/_lwp_park.2 (revision 15c5c5f47235d06ffb52fc67ae524c4a93e97a39)
1.\"	$NetBSD: _lwp_park.2,v 1.13 2022/12/04 16:17:50 uwe Exp $
2.\"
3.\" Copyright (c) 2003, 2007, 2017 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Jason R. Thorpe of Wasabi Systems, Inc, and by Andrew Doran.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
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.
17.\"
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.
29.\"
30.Dd July 30, 2019
31.Dt _LWP_PARK 2
32.Os
33.Sh NAME
34.Nm _lwp_park
35.Nd wait interruptably in the kernel
36.Sh LIBRARY
37.Lb libc
38.Sh SYNOPSIS
39.In lwp.h
40.Ft int
41.Fn _lwp_park "clockid_t clock_id" "int flags" "struct timespec *ts" "lwpid_t unpark" "const void *hint" "const void *unparkhint"
42.Sh DESCRIPTION
43.Fn _lwp_park
44can be used to synchronize access to resources among multiple light-weight
45processes.
46It causes the calling LWP to wait interruptably in the kernel, until one
47of the following conditions is met:
48.Bl -bullet
49.It
50The
51.Fa ts
52argument is
53.Pf non- Dv NULL ,
54and the time it specifies has passed.
55The
56.Fa ts
57time can be a relative interval to wait if the
58.Fa flags
59argument does not contain
60.Dv TIMER_ABSTIME
61or it can be an absolute time.
62The
63.Fa clock_id
64argument contains the clock to be used; it can be:
65.Dv CLOCK_REALTIME
66or
67.Dv CLOCK_MONOTONIC .
68.It
69The LWP receives a directed signal posted using
70.Fn _lwp_kill ,
71or is elected to handle a signal on behalf of its containing process.
72.It
73The LWP is awoken by another LWP in the same process that has made
74a call to
75.Fn _lwp_wakeup .
76.It
77The LWP is awoken by another LWP in the same process that has made
78a call to
79.Fn _lwp_unpark
80or
81.Fn _lwp_unpark_all .
82.El
83.Pp
84If the
85.Fa ts
86argument contains a relative time interval, it will be modified to contain
87the remaining time to sleep when
88.Fn _lwp_park
89returns.
90.Pp
91The preferred method to awaken an LWP sleeping as a result of a call
92to
93.Fn _lwp_park
94is to make a call to
95.Fn _lwp_unpark ,
96or
97.Fn _lwp_unpark_all .
98The
99.Fn _lwp_wakeup
100system call is a more general facility, and requires more resources
101to execute.
102.Pp
103The optional
104.Fa hint
105argument specifies the address of an object upon which the LWP is
106synchronizing.
107When the
108.Fa hint
109value is matched between calls to
110.Fn _lwp_park
111and
112.Fn _lwp_unpark
113or
114.Fn _lwp_unpark_all ,
115it may reduce the time necessary for the system to resume execution
116of waiting LWPs.
117.Pp
118The
119.Fa unpark
120and
121.Fa unparkhint
122arguments can be used to fold a park operation and unpark operation into a
123single system call.
124If
125.Fa unpark
126is non-zero, the system will behave as if the following call had been made
127before the calling thread begins to wait:
128.Pp
129.Dl _lwp_unpark(unpark, unparkhint);
130.Sh RETURN VALUES
131.\" Rv -std _lwp_park
132.\" The "if successful" language in .Rv -std is misleading, but try to
133 \" follow its phrasing as close as possible.
134The
135.Fn _lwp_park
136.\" XXX: TODO: when?  be more precise
137function may return the value of 0.
138Otherwise the value \-1 is returned and the global variable
139.Va errno
140is set to provide more information.
141.Sh ERRORS
142.Bl -tag -width Er
143.It Bq Er EALREADY
144A request was made to wake the LWP before it began to wait in
145the kernel.
146.It Bq Er EINTR
147The LWP has been awoken by a signal or by a call to one of the
148following functions:
149.Fn _lwp_unpark ,
150.Fn _lwp_unpark_all ,
151.Fn _lwp_wakeup .
152.It Bq Er EINVAL
153The time value specified by
154.Fa ts
155is invalid.
156.It Bq Er ESRCH
157No LWP can be found in the current process corresponding to
158.Fa unpark .
159.It Bq Er ETIMEDOUT
160The UTC time specified by
161.Fa ts
162has passed.
163.El
164.Sh SEE ALSO
165.Xr _lwp_unpark 2 ,
166.Xr _lwp_unpark_all 2 ,
167.Xr _lwp_wakeup 2
168.Sh HISTORY
169The
170.Fn _lwp_park
171system call first appeared in
172.Nx 5.0 .
173