xref: /freebsd-13.1/lib/libc/sys/timer_settime.2 (revision b1e515a3)
1*b1e515a3SDavid Xu.\" Copyright (c) 2005 David Xu <[email protected]>
2*b1e515a3SDavid 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.\"
28bb5eebe6SDavid Xu.\" $FreeBSD$
29bb5eebe6SDavid Xu.\"
30bb5eebe6SDavid Xu.Dd Sep 11, 2000
31bb5eebe6SDavid Xu.Dt TIMER_SETTIME 2
32bb5eebe6SDavid Xu.Os
33bb5eebe6SDavid Xu.Sh NAME
34bb5eebe6SDavid Xu.Nm timer_getoverrun
35bb5eebe6SDavid Xu.Nm timer_gettime
36bb5eebe6SDavid Xu.Nm timer_settime
37bb5eebe6SDavid Xu.Nd per-process timers (REALTIME)
38bb5eebe6SDavid Xu.Sh LIBRARY
39bb5eebe6SDavid Xu.Lb libc
40bb5eebe6SDavid Xu.Sh SYNOPSIS
41bb5eebe6SDavid Xu.In time.h
42bb5eebe6SDavid Xu.Ft int
43bb5eebe6SDavid Xu.Fn timer_getoverrun "timer_t timerid"
44bb5eebe6SDavid Xu.Ft int
45bb5eebe6SDavid Xu.Fn timer_gettime "timer_t timerid" "struct itimerspec *value"
46bb5eebe6SDavid Xu.Ft int
47bb5eebe6SDavid Xu.Fn timer_settime "timer_t timerid" "int flags" "const struct itimerspec *restrict value" "struct itimerspec *restrict ovalue"
48bb5eebe6SDavid Xu.Sh DESCRIPTION
49bb5eebe6SDavid XuThe
50bb5eebe6SDavid Xu.Fn timer_gettime
51bb5eebe6SDavid Xufunction stores the amount of time until the specified timer,
52bb5eebe6SDavid Xu.Fa timerid ,
53bb5eebe6SDavid Xuexpires and the reload value of the timer into the space pointed to by the
54bb5eebe6SDavid Xu.Fa value
55bb5eebe6SDavid Xuargument. The it_value member of this structure contains the amount of time
56bb5eebe6SDavid Xubefore the timer expires, or zero if the timer is disarmed. This value is
57bb5eebe6SDavid Xureturned as the interval until timer expiration, even if the timer was armed
58bb5eebe6SDavid Xuwith absolute time. The it_interval member of value contains the reload
59bb5eebe6SDavid Xuvalue last set by
60bb5eebe6SDavid Xu.Fn timer_settime .
61bb5eebe6SDavid Xu.Pp
62bb5eebe6SDavid XuThe
63bb5eebe6SDavid Xu.Fn timer_settime
64bb5eebe6SDavid Xufunction sets the time until the next expiration of the timer specified
65bb5eebe6SDavid Xuby
66bb5eebe6SDavid Xu.Fa timerid
67bb5eebe6SDavid Xufrom the it_value member of the value argument and arm the timer if the
68bb5eebe6SDavid Xuit_value member of value is non-zero. If the specified timer was already
69bb5eebe6SDavid Xuarmed when
70bb5eebe6SDavid Xu.Fn timer_settime
71bb5eebe6SDavid Xuis called, this call resets the time until next expiration to the value
72bb5eebe6SDavid Xuspecified. If the it_value member of value is zero, the timer is disarmed.
73bb5eebe6SDavid XuIf the timer is disarmed, then pending signal is removed.
74bb5eebe6SDavid Xu.Pp
75bb5eebe6SDavid XuIf the flag TIMER_ABSTIME is not set in the argument
76bb5eebe6SDavid Xu.Fa flags ,
77bb5eebe6SDavid Xu.Fn timer_settime
78bb5eebe6SDavid Xubehaves as if the time until next expiration is set to
79bb5eebe6SDavid Xube equal to the interval specified by the it_value member of value. That is,
80bb5eebe6SDavid Xuthe timer expires in it_value nanoseconds from when the call is made. If the
81bb5eebe6SDavid Xuflag TIMER_ABSTIME is set in the argument flags,
82bb5eebe6SDavid Xu.Fn timer_settime
83bb5eebe6SDavid Xubehaves as if the time until next expiration is set to be equal to the
84bb5eebe6SDavid Xudifference between the absolute time specified by the it_value member of
85bb5eebe6SDavid Xuvalue and the current value of the clock associated with
86bb5eebe6SDavid Xu.Fa timerid .
87bb5eebe6SDavid XuThat is, the timer expires when the clock reaches the value specified by the
88bb5eebe6SDavid Xuit_value member of value. If the specified time has already passed, the
89bb5eebe6SDavid Xufunction succeeds and the expiration notification is made.
90bb5eebe6SDavid Xu.Pp
91bb5eebe6SDavid XuThe reload value of the timer is set to the value specified by the it_interval
92bb5eebe6SDavid Xumember of value. When a timer is armed with a non-zero it_interval, a periodic
93bb5eebe6SDavid Xu(or repetitive) timer is specified.
94bb5eebe6SDavid Xu.Pp
95bb5eebe6SDavid XuTime values that are between two consecutive non-negative integer multiples of
96bb5eebe6SDavid Xuthe resolution of the specified timer is rounded up to the larger multiple of
97bb5eebe6SDavid Xuthe resolution. Quantization error will not cause the timer to expire earlier
98bb5eebe6SDavid Xuthan the rounded time value.
99bb5eebe6SDavid Xu.Pp
100bb5eebe6SDavid XuIf the argument ovalue is not NULL, the
101bb5eebe6SDavid Xu.Fn timer_settime
102bb5eebe6SDavid Xufunction stores, in the location referenced by ovalue, a value representing
103bb5eebe6SDavid Xuthe previous amount of time before the timer would have expired, or zero if the
104bb5eebe6SDavid Xutimer was disarmed, together with the previous timer reload value. Timers is not
105bb5eebe6SDavid Xuexpire before their scheduled time.
106bb5eebe6SDavid Xu.Pp
107bb5eebe6SDavid XuOnly a single signal is queued to the process for a given timer at any point in
108bb5eebe6SDavid Xutime. When a timer for which a signal is still pending expires, no signal is
109bb5eebe6SDavid Xuqueued, and a timer overrun will occur. When a timer expiration signal is
110bb5eebe6SDavid Xuaccepted by a process, the
111bb5eebe6SDavid Xu.Fn timer_getoverrun
112bb5eebe6SDavid Xufunction returns the timer expiration overrun count for the specified timer.
113bb5eebe6SDavid XuThe overrun count returned contains the number of extra timer expirations that
114bb5eebe6SDavid Xuoccurred between the time the signal was generated (queued) and when it was
115bb5eebe6SDavid Xuaccepted, up to but not including an maximum of {DELAYTIMER_MAX}. If the number of
116bb5eebe6SDavid Xusuch extra expirations is greater than or equal to {DELAYTIMER_MAX}, then the
117bb5eebe6SDavid Xuoverrun count is set to {DELAYTIMER_MAX}. The value returned by
118bb5eebe6SDavid Xu.Fn timer_getoverrun
119bb5eebe6SDavid Xuapplies to the most recent expiration signal acceptance for the timer. If no
120bb5eebe6SDavid Xuexpiration signal has been delivered for the timer, the return value of
121bb5eebe6SDavid Xu.Fn timer_getoverrun
122bb5eebe6SDavid Xuis unspecified.
123bb5eebe6SDavid Xu.Sh RETURN VALUES
124bb5eebe6SDavid XuIf the
125bb5eebe6SDavid Xu.Fn timer_getoverrun
126bb5eebe6SDavid Xufunction succeeds, it returns the timer expiration overrun count as explained
127bb5eebe6SDavid Xuabove.
128bb5eebe6SDavid Xu.Pp
129bb5eebe6SDavid XuIf the
130bb5eebe6SDavid Xu.Fn timer_gettime
131bb5eebe6SDavid Xuor
132bb5eebe6SDavid Xu.Fn timer_settime
133bb5eebe6SDavid Xufunctions succeed, a value of 0 is returned.
134bb5eebe6SDavid Xu.Pp
135bb5eebe6SDavid XuIf an error occurs for any of these functions, the value -1 is returned, and
136bb5eebe6SDavid Xuerrno set to indicate the error.
137bb5eebe6SDavid Xu.Sh ERRORS
138bb5eebe6SDavid XuThe
139bb5eebe6SDavid Xu.Fn timer_settime
140bb5eebe6SDavid Xuwill fail if:
141bb5eebe6SDavid Xu.Bl -tag -width Er
142bb5eebe6SDavid Xu.It Bq Er EINVAL
143bb5eebe6SDavid XuA value structure specified a nanosecond value less than zero or greater than
144bb5eebe6SDavid Xuor equal to 1000 million, and the it_value member of that structure did not
145bb5eebe6SDavid Xuspecify zero seconds and nanoseconds.
146bb5eebe6SDavid Xu.El
147bb5eebe6SDavid Xu.Pp
148bb5eebe6SDavid XuThese functions may fail if:
149bb5eebe6SDavid Xu.Bl -tag -width Er
150bb5eebe6SDavid Xu.It Bq Er EINVAL
151bb5eebe6SDavid XuThe
152bb5eebe6SDavid Xu.Fa timerid
153bb5eebe6SDavid Xuargument does not correspond to an ID returned by
154bb5eebe6SDavid Xu.Fn timer_create
155bb5eebe6SDavid Xubut not yet deleted by
156bb5eebe6SDavid Xu.Fn timer_delete .
157bb5eebe6SDavid Xu.El
158bb5eebe6SDavid Xu.Pp
159bb5eebe6SDavid XuThe timer_settime() function may fail if:
160bb5eebe6SDavid Xu.Bl -tag -width Er
161bb5eebe6SDavid Xu.It Bq Er EINVAL
162bb5eebe6SDavid XuThe it_interval member of value is not zero and the timer was created with
163bb5eebe6SDavid Xunotification by creation of a new thread ( sigev_sigev_notify was SIGEV_THREAD)
164bb5eebe6SDavid Xuand a fixed stack address has been set in the thread attribute pointed to by
165bb5eebe6SDavid Xusigev_notify_attributes.
166bb5eebe6SDavid Xu.El
167bb5eebe6SDavid Xu.Pp
168bb5eebe6SDavid XuThe
169bb5eebe6SDavid Xu.Fn timer_gettime
170bb5eebe6SDavid Xuand
171bb5eebe6SDavid Xu.Fn timer_settime
172bb5eebe6SDavid Xumay fail if:
173bb5eebe6SDavid Xu.Bl -tag -width Er
174bb5eebe6SDavid Xu.It Bq Er EFAULT
175bb5eebe6SDavid XuAny arguments point outside the allocated address space or there is a
176bb5eebe6SDavid Xumemory protection fault.
177bb5eebe6SDavid Xu.El
178bb5eebe6SDavid Xu.Sh SEE ALSO
179bb5eebe6SDavid Xu.Xr clock_getres 2 ,
180bb5eebe6SDavid Xu.Xr timer_create 2
181bb5eebe6SDavid Xu.Sh STANDARDS
182bb5eebe6SDavid XuThe
183bb5eebe6SDavid Xu.Fn timer_getoverrun ,
184bb5eebe6SDavid Xu.Fn timer_gettime ,
185bb5eebe6SDavid Xuand
186bb5eebe6SDavid Xu.Fn timer_settime
187bb5eebe6SDavid Xufunction conform to
188bb5eebe6SDavid Xu.St -p1003.1-96 .
189