xref: /freebsd-14.2/lib/libc/sys/timer_create.2 (revision fa9896e0)
15507a2aeSRuslan Ermilov.\" Copyright (c) 2005 David Xu <[email protected]>
2b1e515a3SDavid Xu.\" All rights reserved.
3bb5eebe6SDavid Xu.\"
4bb5eebe6SDavid Xu.\" Redistribution and use in source and binary forms, with or without
5bb5eebe6SDavid Xu.\" modification, are permitted provided that the following conditions
6bb5eebe6SDavid Xu.\" are met:
7bb5eebe6SDavid Xu.\" 1. Redistributions of source code must retain the above copyright
8bb5eebe6SDavid Xu.\"    notice(s), this list of conditions and the following disclaimer as
9bb5eebe6SDavid Xu.\"    the first lines of this file unmodified other than the possible
10bb5eebe6SDavid Xu.\"    addition of one or more copyright notices.
11bb5eebe6SDavid Xu.\" 2. Redistributions in binary form must reproduce the above copyright
12bb5eebe6SDavid Xu.\"    notice(s), this list of conditions and the following disclaimer in
13bb5eebe6SDavid Xu.\"    the documentation and/or other materials provided with the
14bb5eebe6SDavid Xu.\"    distribution.
15bb5eebe6SDavid Xu.\"
16bb5eebe6SDavid Xu.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
17bb5eebe6SDavid Xu.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18bb5eebe6SDavid Xu.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19bb5eebe6SDavid Xu.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
20bb5eebe6SDavid Xu.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21bb5eebe6SDavid Xu.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22bb5eebe6SDavid Xu.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23bb5eebe6SDavid Xu.\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24bb5eebe6SDavid Xu.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25bb5eebe6SDavid Xu.\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26bb5eebe6SDavid Xu.\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27bb5eebe6SDavid Xu.\"
28*463970daSJohn Baldwin.Dd July 15, 2016
29bb5eebe6SDavid Xu.Dt TIMER_CREATE 2
30bb5eebe6SDavid Xu.Os
31bb5eebe6SDavid Xu.Sh NAME
32bb5eebe6SDavid Xu.Nm timer_create
335507a2aeSRuslan Ermilov.Nd "create a per-process timer (REALTIME)"
34bb5eebe6SDavid Xu.Sh LIBRARY
35e9311906SDavid Xu.Lb librt
36bb5eebe6SDavid Xu.Sh SYNOPSIS
37bb5eebe6SDavid Xu.In time.h
38a28d1439SDaniel Gerzo.In signal.h
39bb5eebe6SDavid Xu.Ft int
405507a2aeSRuslan Ermilov.Fo timer_create
415507a2aeSRuslan Ermilov.Fa "clockid_t clockid" "struct sigevent *restrict evp"
425507a2aeSRuslan Ermilov.Fa "timer_t *restrict timerid"
435507a2aeSRuslan Ermilov.Fc
44bb5eebe6SDavid Xu.Sh DESCRIPTION
45bb5eebe6SDavid XuThe
46bb5eebe6SDavid Xu.Fn timer_create
475507a2aeSRuslan Ermilovsystem call creates a per-process timer using the specified clock,
48bb5eebe6SDavid Xu.Fa clock_id ,
495507a2aeSRuslan Ermilovas the timing base.
505507a2aeSRuslan ErmilovThe
51bb5eebe6SDavid Xu.Fn timer_create
525507a2aeSRuslan Ermilovsystem call returns, in the location referenced by
53bb5eebe6SDavid Xu.Fa timerid ,
545507a2aeSRuslan Ermilova timer ID of type
555507a2aeSRuslan Ermilov.Vt timer_t
565507a2aeSRuslan Ermilovused to identify the timer in timer requests.
57bb5eebe6SDavid XuThis timer ID is unique within the calling process until the timer is deleted.
58bb5eebe6SDavid XuThe particular clock,
59bb5eebe6SDavid Xu.Fa clock_id ,
60bb5eebe6SDavid Xuis defined in
61bb5eebe6SDavid Xu.In time.h .
62bb5eebe6SDavid XuThe timer whose ID is returned is in a disarmed state upon return from
63bb5eebe6SDavid Xu.Fn timer_create .
64bb5eebe6SDavid Xu.Pp
65bb5eebe6SDavid XuThe
66bb5eebe6SDavid Xu.Fa evp
675507a2aeSRuslan Ermilovargument, if
685507a2aeSRuslan Ermilov.Pf non- Dv NULL ,
695507a2aeSRuslan Ermilovpoints to a
705507a2aeSRuslan Ermilov.Vt sigevent
715507a2aeSRuslan Ermilovstructure.
725507a2aeSRuslan ErmilovThis structure,
73bb5eebe6SDavid Xuallocated by the application, defines the asynchronous notification to occur
745507a2aeSRuslan Ermilovwhen the timer expires.
75*463970daSJohn Baldwin.Pp
76*463970daSJohn BaldwinIf
77*463970daSJohn Baldwin.Fa evp->sigev_notify
78*463970daSJohn Baldwinis
79*463970daSJohn Baldwin.Dv SIGEV_SIGNO
80*463970daSJohn Baldwinor
81*463970daSJohn Baldwin.Dv SIGEV_THREAD_ID ,
82*463970daSJohn Baldwinthe signal specified in
83*463970daSJohn Baldwin.Fa evp->sigev_signo
84*463970daSJohn Baldwinwill be sent to the calling process
85*463970daSJohn Baldwin.Pq Dv SIGEV_SIGNO
86*463970daSJohn Baldwinor to the thread whose LWP ID is
87*463970daSJohn Baldwin.Fa evp->sigev_notify_thread_id
88*463970daSJohn Baldwin.Pq Dv SIGEV_THREAD_ID .
89*463970daSJohn BaldwinThe information for the queued signal will include:
90*463970daSJohn Baldwin.Bl -column ".Va si_value"
91*463970daSJohn Baldwin.It Sy Member Ta Sy Value
92*463970daSJohn Baldwin.It Va si_code Ta Dv SI_TIMER
93*463970daSJohn Baldwin.It Va si_value Ta
94*463970daSJohn Baldwinthe value stored in
95*463970daSJohn Baldwin.Fa evp->sigev_value
96*463970daSJohn Baldwin.It Va si_timerid Ta timer ID
97*463970daSJohn Baldwin.It Va si_overrun Ta timer overrun count
98*463970daSJohn Baldwin.It Va si_errno Ta
99*463970daSJohn BaldwinIf timer overrun is
100*463970daSJohn Baldwin.Brq Dv DELAYTIMER_MAX ,
101*463970daSJohn Baldwinan error code defined in
102*463970daSJohn Baldwin.In errno.h
103*463970daSJohn Baldwin.El
104*463970daSJohn Baldwin.Pp
1055507a2aeSRuslan ErmilovIf the
106bb5eebe6SDavid Xu.Fa evp
1075507a2aeSRuslan Ermilovargument is
1085507a2aeSRuslan Ermilov.Dv NULL ,
1095507a2aeSRuslan Ermilovthe effect is as if the
1105507a2aeSRuslan Ermilov.Fa evp
1115507a2aeSRuslan Ermilovargument pointed to a
1125507a2aeSRuslan Ermilov.Vt sigevent
1135507a2aeSRuslan Ermilovstructure with the
1145507a2aeSRuslan Ermilov.Va sigev_notify
1155507a2aeSRuslan Ermilovmember having the value
1165507a2aeSRuslan Ermilov.Dv SIGEV_SIGNAL ,
1175507a2aeSRuslan Ermilovthe
1185507a2aeSRuslan Ermilov.Va sigev_signo
119*463970daSJohn Baldwinhaving a default signal number
120*463970daSJohn Baldwin.Pq Dv SIGALRM ,
121*463970daSJohn Baldwinand the
1225507a2aeSRuslan Ermilov.Va sigev_value
1235507a2aeSRuslan Ermilovmember having
124bb5eebe6SDavid Xuthe value of the timer ID.
125bb5eebe6SDavid Xu.Pp
126*463970daSJohn BaldwinThis implementation supports a
1275507a2aeSRuslan Ermilov.Fa clock_id
1285507a2aeSRuslan Ermilovof
1295507a2aeSRuslan Ermilov.Dv CLOCK_REALTIME
1305507a2aeSRuslan Ermilovor
1315507a2aeSRuslan Ermilov.Dv CLOCK_MONOTONIC .
132bb5eebe6SDavid Xu.Pp
1335507a2aeSRuslan ErmilovIf
134a28d1439SDaniel Gerzo.Fa evp->sigev_notify
1355507a2aeSRuslan Ermilovis
1365507a2aeSRuslan Ermilov.Dv SIGEV_THREAD
1375507a2aeSRuslan Ermilovand
1385507a2aeSRuslan Ermilov.Fa sev->sigev_notify_attributes
1395507a2aeSRuslan Ermilovis not
1405507a2aeSRuslan Ermilov.Dv NULL ,
1415507a2aeSRuslan Ermilovif the attribute pointed to by
1425507a2aeSRuslan Ermilov.Fa sev->sigev_notify_attributes
1435507a2aeSRuslan Ermilovhas
144bb5eebe6SDavid Xua thread stack address specified by a call to
145bb5eebe6SDavid Xu.Fn pthread_attr_setstack
146bb5eebe6SDavid Xuor
147bb5eebe6SDavid Xu.Fn pthread_attr_setstackaddr ,
148bb5eebe6SDavid Xuthe results are unspecified if the signal is generated more than once.
149bb5eebe6SDavid Xu.Sh RETURN VALUES
150bb5eebe6SDavid XuIf the call succeeds,
151bb5eebe6SDavid Xu.Fn timer_create
1525507a2aeSRuslan Ermilovreturns zero and updates the location referenced by
153bb5eebe6SDavid Xu.Fa timerid
1545507a2aeSRuslan Ermilovto a
1555507a2aeSRuslan Ermilov.Vt timer_t ,
1565507a2aeSRuslan Ermilovwhich can be passed to the per-process timer calls.
1575507a2aeSRuslan ErmilovIf an error
1585507a2aeSRuslan Ermilovoccurs, the system call returns a value of \-1
1595507a2aeSRuslan Ermilovand the global variable
1605507a2aeSRuslan Ermilov.Va errno
1615507a2aeSRuslan Ermilovis set to indicate the
1625507a2aeSRuslan Ermiloverror.
1635507a2aeSRuslan ErmilovThe value of
1645507a2aeSRuslan Ermilov.Fa timerid
1655507a2aeSRuslan Ermilovis undefined if an error occurs.
166bb5eebe6SDavid Xu.Sh ERRORS
167bb5eebe6SDavid XuThe
168bb5eebe6SDavid Xu.Fn timer_create
1695507a2aeSRuslan Ermilovsystem call
170bb5eebe6SDavid Xuwill fail if:
171bb5eebe6SDavid Xu.Bl -tag -width Er
172bb5eebe6SDavid Xu.It Bq Er EAGAIN
173bb5eebe6SDavid XuThe calling process has already created all of the timers it is allowed by
1745507a2aeSRuslan Ermilovthis implementation.
175bb5eebe6SDavid Xu.It Bq Er EINVAL
176bb5eebe6SDavid XuThe specified clock ID is not supported.
177*463970daSJohn Baldwin.It Bq Er EINVAL
178*463970daSJohn BaldwinThe specified asynchronous notification method is not supported.
179bb5eebe6SDavid Xu.It Bq Er EFAULT
180bb5eebe6SDavid XuAny arguments point outside the allocated address space or there is a
181bb5eebe6SDavid Xumemory protection fault.
182bb5eebe6SDavid Xu.El
183bb5eebe6SDavid Xu.Sh SEE ALSO
184bb5eebe6SDavid Xu.Xr clock_getres 2 ,
185bb5eebe6SDavid Xu.Xr timer_delete 2 ,
18652f047eeSSergey Kandaurov.Xr timer_getoverrun 2 ,
187*463970daSJohn Baldwin.Xr sigevent 3 ,
188412295fdSDavid Xu.Xr siginfo 3
189bb5eebe6SDavid Xu.Sh STANDARDS
190bb5eebe6SDavid XuThe
191bb5eebe6SDavid Xu.Fn timer_create
1925507a2aeSRuslan Ermilovsystem call conforms to
1939f63b422SGlen Barber.St -p1003.1-2004 .
1946f59c4c0SDavid Xu.Sh HISTORY
195a73a3ab5SRuslan ErmilovSupport for
196a73a3ab5SRuslan Ermilov.Tn POSIX
197a73a3ab5SRuslan Ermilovper-process timer first appeared in
1986f59c4c0SDavid Xu.Fx 7.0 .
199