xref: /freebsd-14.2/lib/libc/sys/timer_settime.2 (revision bb5eebe6)
1.\"
2.\" Redistribution and use in source and binary forms, with or without
3.\" modification, are permitted provided that the following conditions
4.\" are met:
5.\" 1. Redistributions of source code must retain the above copyright
6.\"    notice(s), this list of conditions and the following disclaimer as
7.\"    the first lines of this file unmodified other than the possible
8.\"    addition of one or more copyright notices.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice(s), this list of conditions and the following disclaimer in
11.\"    the documentation and/or other materials provided with the
12.\"    distribution.
13.\"
14.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
15.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
18.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
21.\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
23.\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
24.\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25.\"
26.\" $FreeBSD$
27.\"
28.Dd Sep 11, 2000
29.Dt TIMER_SETTIME 2
30.Os
31.Sh NAME
32.Nm timer_getoverrun
33.Nm timer_gettime
34.Nm timer_settime
35.Nd per-process timers (REALTIME)
36.Sh LIBRARY
37.Lb libc
38.Sh SYNOPSIS
39.In time.h
40.Ft int
41.Fn timer_getoverrun "timer_t timerid"
42.Ft int
43.Fn timer_gettime "timer_t timerid" "struct itimerspec *value"
44.Ft int
45.Fn timer_settime "timer_t timerid" "int flags" "const struct itimerspec *restrict value" "struct itimerspec *restrict ovalue"
46.Sh DESCRIPTION
47The
48.Fn timer_gettime
49function stores the amount of time until the specified timer,
50.Fa timerid ,
51expires and the reload value of the timer into the space pointed to by the
52.Fa value
53argument. The it_value member of this structure contains the amount of time
54before the timer expires, or zero if the timer is disarmed. This value is
55returned as the interval until timer expiration, even if the timer was armed
56with absolute time. The it_interval member of value contains the reload
57value last set by
58.Fn timer_settime .
59.Pp
60The
61.Fn timer_settime
62function sets the time until the next expiration of the timer specified
63by
64.Fa timerid
65from the it_value member of the value argument and arm the timer if the
66it_value member of value is non-zero. If the specified timer was already
67armed when
68.Fn timer_settime
69is called, this call resets the time until next expiration to the value
70specified. If the it_value member of value is zero, the timer is disarmed.
71If the timer is disarmed, then pending signal is removed.
72.Pp
73If the flag TIMER_ABSTIME is not set in the argument
74.Fa flags ,
75.Fn timer_settime
76behaves as if the time until next expiration is set to
77be equal to the interval specified by the it_value member of value. That is,
78the timer expires in it_value nanoseconds from when the call is made. If the
79flag TIMER_ABSTIME is set in the argument flags,
80.Fn timer_settime
81behaves as if the time until next expiration is set to be equal to the
82difference between the absolute time specified by the it_value member of
83value and the current value of the clock associated with
84.Fa timerid .
85That is, the timer expires when the clock reaches the value specified by the
86it_value member of value. If the specified time has already passed, the
87function succeeds and the expiration notification is made.
88.Pp
89The reload value of the timer is set to the value specified by the it_interval
90member of value. When a timer is armed with a non-zero it_interval, a periodic
91(or repetitive) timer is specified.
92.Pp
93Time values that are between two consecutive non-negative integer multiples of
94the resolution of the specified timer is rounded up to the larger multiple of
95the resolution. Quantization error will not cause the timer to expire earlier
96than the rounded time value.
97.Pp
98If the argument ovalue is not NULL, the
99.Fn timer_settime
100function stores, in the location referenced by ovalue, a value representing
101the previous amount of time before the timer would have expired, or zero if the
102timer was disarmed, together with the previous timer reload value. Timers is not
103expire before their scheduled time.
104.Pp
105Only a single signal is queued to the process for a given timer at any point in
106time. When a timer for which a signal is still pending expires, no signal is
107queued, and a timer overrun will occur. When a timer expiration signal is
108accepted by a process, the
109.Fn timer_getoverrun
110function returns the timer expiration overrun count for the specified timer.
111The overrun count returned contains the number of extra timer expirations that
112occurred between the time the signal was generated (queued) and when it was
113accepted, up to but not including an maximum of {DELAYTIMER_MAX}. If the number of
114such extra expirations is greater than or equal to {DELAYTIMER_MAX}, then the
115overrun count is set to {DELAYTIMER_MAX}. The value returned by
116.Fn timer_getoverrun
117applies to the most recent expiration signal acceptance for the timer. If no
118expiration signal has been delivered for the timer, the return value of
119.Fn timer_getoverrun
120is unspecified.
121.Sh RETURN VALUES
122If the
123.Fn timer_getoverrun
124function succeeds, it returns the timer expiration overrun count as explained
125above.
126.Pp
127If the
128.Fn timer_gettime
129or
130.Fn timer_settime
131functions succeed, a value of 0 is returned.
132.Pp
133If an error occurs for any of these functions, the value -1 is returned, and
134errno set to indicate the error.
135.Sh ERRORS
136The
137.Fn timer_settime
138will fail if:
139.Bl -tag -width Er
140.It Bq Er EINVAL
141A value structure specified a nanosecond value less than zero or greater than
142or equal to 1000 million, and the it_value member of that structure did not
143specify zero seconds and nanoseconds.
144.El
145.Pp
146These functions may fail if:
147.Bl -tag -width Er
148.It Bq Er EINVAL
149The
150.Fa timerid
151argument does not correspond to an ID returned by
152.Fn timer_create
153but not yet deleted by
154.Fn timer_delete .
155.El
156.Pp
157The timer_settime() function may fail if:
158.Bl -tag -width Er
159.It Bq Er EINVAL
160The it_interval member of value is not zero and the timer was created with
161notification by creation of a new thread ( sigev_sigev_notify was SIGEV_THREAD)
162and a fixed stack address has been set in the thread attribute pointed to by
163sigev_notify_attributes.
164.El
165.Pp
166The
167.Fn timer_gettime
168and
169.Fn timer_settime
170may fail if:
171.Bl -tag -width Er
172.It Bq Er EFAULT
173Any arguments point outside the allocated address space or there is a
174memory protection fault.
175.El
176.Sh SEE ALSO
177.Xr clock_getres 2 ,
178.Xr timer_create 2
179.Sh STANDARDS
180The
181.Fn timer_getoverrun ,
182.Fn timer_gettime ,
183and
184.Fn timer_settime
185function conform to
186.St -p1003.1-96 .
187