xref: /freebsd/lib/libsys/timer_create.2 (revision a90b9d0159070121c221b966469c3e36d912bf82)
1.\" Copyright (c) 2005 David Xu <davidxu@FreeBSD.org>
2.\" 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
13.\"    the documentation and/or other materials provided with the
14.\"    distribution.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
17.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
20.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23.\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25.\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26.\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27.\"
28.Dd July 15, 2016
29.Dt TIMER_CREATE 2
30.Os
31.Sh NAME
32.Nm timer_create
33.Nd "create a per-process timer (REALTIME)"
34.Sh LIBRARY
35.Lb librt
36.Sh SYNOPSIS
37.In time.h
38.In signal.h
39.Ft int
40.Fo timer_create
41.Fa "clockid_t clockid" "struct sigevent *restrict evp"
42.Fa "timer_t *restrict timerid"
43.Fc
44.Sh DESCRIPTION
45The
46.Fn timer_create
47system call creates a per-process timer using the specified clock,
48.Fa clock_id ,
49as the timing base.
50The
51.Fn timer_create
52system call returns, in the location referenced by
53.Fa timerid ,
54a timer ID of type
55.Vt timer_t
56used to identify the timer in timer requests.
57This timer ID is unique within the calling process until the timer is deleted.
58The particular clock,
59.Fa clock_id ,
60is defined in
61.In time.h .
62The timer whose ID is returned is in a disarmed state upon return from
63.Fn timer_create .
64.Pp
65The
66.Fa evp
67argument, if
68.Pf non- Dv NULL ,
69points to a
70.Vt sigevent
71structure.
72This structure,
73allocated by the application, defines the asynchronous notification to occur
74when the timer expires.
75.Pp
76If
77.Fa evp->sigev_notify
78is
79.Dv SIGEV_SIGNO
80or
81.Dv SIGEV_THREAD_ID ,
82the signal specified in
83.Fa evp->sigev_signo
84will be sent to the calling process
85.Pq Dv SIGEV_SIGNO
86or to the thread whose LWP ID is
87.Fa evp->sigev_notify_thread_id
88.Pq Dv SIGEV_THREAD_ID .
89The information for the queued signal will include:
90.Bl -column ".Va si_value"
91.It Sy Member Ta Sy Value
92.It Va si_code Ta Dv SI_TIMER
93.It Va si_value Ta
94the value stored in
95.Fa evp->sigev_value
96.It Va si_timerid Ta timer ID
97.It Va si_overrun Ta timer overrun count
98.It Va si_errno Ta
99If timer overrun is
100.Brq Dv DELAYTIMER_MAX ,
101an error code defined in
102.In errno.h
103.El
104.Pp
105If the
106.Fa evp
107argument is
108.Dv NULL ,
109the effect is as if the
110.Fa evp
111argument pointed to a
112.Vt sigevent
113structure with the
114.Va sigev_notify
115member having the value
116.Dv SIGEV_SIGNAL ,
117the
118.Va sigev_signo
119having a default signal number
120.Pq Dv SIGALRM ,
121and the
122.Va sigev_value
123member having
124the value of the timer ID.
125.Pp
126This implementation supports a
127.Fa clock_id
128of
129.Dv CLOCK_REALTIME
130or
131.Dv CLOCK_MONOTONIC .
132.Pp
133If
134.Fa evp->sigev_notify
135is
136.Dv SIGEV_THREAD
137and
138.Fa sev->sigev_notify_attributes
139is not
140.Dv NULL ,
141if the attribute pointed to by
142.Fa sev->sigev_notify_attributes
143has
144a thread stack address specified by a call to
145.Fn pthread_attr_setstack
146or
147.Fn pthread_attr_setstackaddr ,
148the results are unspecified if the signal is generated more than once.
149.Sh RETURN VALUES
150If the call succeeds,
151.Fn timer_create
152returns zero and updates the location referenced by
153.Fa timerid
154to a
155.Vt timer_t ,
156which can be passed to the per-process timer calls.
157If an error
158occurs, the system call returns a value of \-1
159and the global variable
160.Va errno
161is set to indicate the
162error.
163The value of
164.Fa timerid
165is undefined if an error occurs.
166.Sh ERRORS
167The
168.Fn timer_create
169system call
170will fail if:
171.Bl -tag -width Er
172.It Bq Er EAGAIN
173The calling process has already created all of the timers it is allowed by
174this implementation.
175.It Bq Er EINVAL
176The specified clock ID is not supported.
177.It Bq Er EINVAL
178The specified asynchronous notification method is not supported.
179.It Bq Er EFAULT
180Any arguments point outside the allocated address space or there is a
181memory protection fault.
182.El
183.Sh SEE ALSO
184.Xr clock_getres 2 ,
185.Xr timer_delete 2 ,
186.Xr timer_getoverrun 2 ,
187.Xr sigevent 3 ,
188.Xr siginfo 3
189.Sh STANDARDS
190The
191.Fn timer_create
192system call conforms to
193.St -p1003.1-2004 .
194.Sh HISTORY
195Support for
196.Tn POSIX
197per-process timer first appeared in
198.Fx 7.0 .
199