1*5507a2aeSRuslan 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.\" 28bb5eebe6SDavid Xu.\" $FreeBSD$ 29bb5eebe6SDavid Xu.\" 30*5507a2aeSRuslan Ermilov.Dd September 11, 2000 31bb5eebe6SDavid Xu.Dt TIMER_SETTIME 2 32bb5eebe6SDavid Xu.Os 33bb5eebe6SDavid Xu.Sh NAME 34*5507a2aeSRuslan Ermilov.Nm timer_getoverrun , 35*5507a2aeSRuslan Ermilov.Nm timer_gettime , 36bb5eebe6SDavid Xu.Nm timer_settime 37*5507a2aeSRuslan Ermilov.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 47*5507a2aeSRuslan Ermilov.Fo timer_settime 48*5507a2aeSRuslan Ermilov.Fa "timer_t timerid" "int flags" "const struct itimerspec *restrict value" 49*5507a2aeSRuslan Ermilov.Fa "struct itimerspec *restrict ovalue" 50*5507a2aeSRuslan Ermilov.Fc 51bb5eebe6SDavid Xu.Sh DESCRIPTION 52bb5eebe6SDavid XuThe 53bb5eebe6SDavid Xu.Fn timer_gettime 54*5507a2aeSRuslan Ermilovsystem call stores the amount of time until the specified timer, 55bb5eebe6SDavid Xu.Fa timerid , 56bb5eebe6SDavid Xuexpires and the reload value of the timer into the space pointed to by the 57bb5eebe6SDavid Xu.Fa value 58*5507a2aeSRuslan Ermilovargument. 59*5507a2aeSRuslan ErmilovThe 60*5507a2aeSRuslan Ermilov.Va it_value 61*5507a2aeSRuslan Ermilovmember of this structure contains the amount of time 62*5507a2aeSRuslan Ermilovbefore the timer expires, or zero if the timer is disarmed. 63*5507a2aeSRuslan ErmilovThis value is 64bb5eebe6SDavid Xureturned as the interval until timer expiration, even if the timer was armed 65*5507a2aeSRuslan Ermilovwith absolute time. 66*5507a2aeSRuslan ErmilovThe 67*5507a2aeSRuslan Ermilov.Va it_interval 68*5507a2aeSRuslan Ermilovmember of 69*5507a2aeSRuslan Ermilov.Fa value 70*5507a2aeSRuslan Ermilovcontains the reload 71bb5eebe6SDavid Xuvalue last set by 72bb5eebe6SDavid Xu.Fn timer_settime . 73bb5eebe6SDavid Xu.Pp 74bb5eebe6SDavid XuThe 75bb5eebe6SDavid Xu.Fn timer_settime 76*5507a2aeSRuslan Ermilovsystem call sets the time until the next expiration of the timer specified 77bb5eebe6SDavid Xuby 78bb5eebe6SDavid Xu.Fa timerid 79*5507a2aeSRuslan Ermilovfrom the 80*5507a2aeSRuslan Ermilov.Va it_value 81*5507a2aeSRuslan Ermilovmember of the 82*5507a2aeSRuslan Ermilov.Fa value 83*5507a2aeSRuslan Ermilovargument and arms the timer if the 84*5507a2aeSRuslan Ermilov.Va it_value 85*5507a2aeSRuslan Ermilovmember of 86*5507a2aeSRuslan Ermilov.Fa value 87*5507a2aeSRuslan Ermilovis non-zero. 88*5507a2aeSRuslan ErmilovIf the specified timer was already 89bb5eebe6SDavid Xuarmed when 90bb5eebe6SDavid Xu.Fn timer_settime 91bb5eebe6SDavid Xuis called, this call resets the time until next expiration to the value 92*5507a2aeSRuslan Ermilovspecified. 93*5507a2aeSRuslan ErmilovIf the 94*5507a2aeSRuslan Ermilov.Va it_value 95*5507a2aeSRuslan Ermilovmember of 96*5507a2aeSRuslan Ermilov.Fa value 97*5507a2aeSRuslan Ermilovis zero, the timer is disarmed. 98bb5eebe6SDavid XuIf the timer is disarmed, then pending signal is removed. 99bb5eebe6SDavid Xu.Pp 100*5507a2aeSRuslan ErmilovIf the flag 101*5507a2aeSRuslan Ermilov.Dv TIMER_ABSTIME 102*5507a2aeSRuslan Ermilovis not set in the argument 103bb5eebe6SDavid Xu.Fa flags , 104bb5eebe6SDavid Xu.Fn timer_settime 105bb5eebe6SDavid Xubehaves as if the time until next expiration is set to 106*5507a2aeSRuslan Ermilovbe equal to the interval specified by the 107*5507a2aeSRuslan Ermilov.Va it_value 108*5507a2aeSRuslan Ermilovmember of 109*5507a2aeSRuslan Ermilov.Fa value . 110*5507a2aeSRuslan ErmilovThat is, 111*5507a2aeSRuslan Ermilovthe timer expires in 112*5507a2aeSRuslan Ermilov.Va it_value 113*5507a2aeSRuslan Ermilovnanoseconds from when the call is made. 114*5507a2aeSRuslan ErmilovIf the flag 115*5507a2aeSRuslan Ermilov.Dv TIMER_ABSTIME 116*5507a2aeSRuslan Ermilovis set in the argument 117*5507a2aeSRuslan Ermilov.Fa flags , 118bb5eebe6SDavid Xu.Fn timer_settime 119bb5eebe6SDavid Xubehaves as if the time until next expiration is set to be equal to the 120bb5eebe6SDavid Xudifference between the absolute time specified by the it_value member of 121bb5eebe6SDavid Xuvalue and the current value of the clock associated with 122bb5eebe6SDavid Xu.Fa timerid . 123bb5eebe6SDavid XuThat is, the timer expires when the clock reaches the value specified by the 124*5507a2aeSRuslan Ermilov.Va it_value 125*5507a2aeSRuslan Ermilovmember of 126*5507a2aeSRuslan Ermilov.Fa value . 127*5507a2aeSRuslan ErmilovIf the specified time has already passed, the 128*5507a2aeSRuslan Ermilovsystem call succeeds and the expiration notification is made. 129bb5eebe6SDavid Xu.Pp 130*5507a2aeSRuslan ErmilovThe reload value of the timer is set to the value specified by the 131*5507a2aeSRuslan Ermilov.Va it_interval 132*5507a2aeSRuslan Ermilovmember of 133*5507a2aeSRuslan Ermilov.Fa value . 134*5507a2aeSRuslan ErmilovWhen a timer is armed with a non-zero 135*5507a2aeSRuslan Ermilov.Va it_interval , 136*5507a2aeSRuslan Ermilova periodic 137bb5eebe6SDavid Xu(or repetitive) timer is specified. 138bb5eebe6SDavid Xu.Pp 139bb5eebe6SDavid XuTime values that are between two consecutive non-negative integer multiples of 140*5507a2aeSRuslan Ermilovthe resolution of the specified timer are rounded up to the larger multiple of 141*5507a2aeSRuslan Ermilovthe resolution. 142*5507a2aeSRuslan ErmilovQuantization error will not cause the timer to expire earlier 143bb5eebe6SDavid Xuthan the rounded time value. 144bb5eebe6SDavid Xu.Pp 145*5507a2aeSRuslan ErmilovIf the argument 146*5507a2aeSRuslan Ermilov.Fa ovalue 147*5507a2aeSRuslan Ermilovis not 148*5507a2aeSRuslan Ermilov.Dv NULL , 149*5507a2aeSRuslan Ermilovthe 150bb5eebe6SDavid Xu.Fn timer_settime 151*5507a2aeSRuslan Ermilovsystem call stores, in the location referenced by 152*5507a2aeSRuslan Ermilov.Fa ovalue , 153*5507a2aeSRuslan Ermilova value representing 154bb5eebe6SDavid Xuthe previous amount of time before the timer would have expired, or zero if the 155*5507a2aeSRuslan Ermilovtimer was disarmed, together with the previous timer reload value. 156*5507a2aeSRuslan ErmilovTimers do not 157bb5eebe6SDavid Xuexpire before their scheduled time. 158bb5eebe6SDavid Xu.Pp 159bb5eebe6SDavid XuOnly a single signal is queued to the process for a given timer at any point in 160*5507a2aeSRuslan Ermilovtime. 161*5507a2aeSRuslan ErmilovWhen a timer for which a signal is still pending expires, no signal is 162*5507a2aeSRuslan Ermilovqueued, and a timer overrun will occur. 163*5507a2aeSRuslan ErmilovWhen a timer expiration signal is 164bb5eebe6SDavid Xuaccepted by a process, the 165bb5eebe6SDavid Xu.Fn timer_getoverrun 166*5507a2aeSRuslan Ermilovsystem call returns the timer expiration overrun count for the specified timer. 167bb5eebe6SDavid XuThe overrun count returned contains the number of extra timer expirations that 168bb5eebe6SDavid Xuoccurred between the time the signal was generated (queued) and when it was 169*5507a2aeSRuslan Ermilovaccepted, up to but not including an maximum of 170*5507a2aeSRuslan Ermilov.Brq Dv DELAYTIMER_MAX . 171*5507a2aeSRuslan ErmilovIf the number of 172*5507a2aeSRuslan Ermilovsuch extra expirations is greater than or equal to 173*5507a2aeSRuslan Ermilov.Brq Dv DELAYTIMER_MAX , 174*5507a2aeSRuslan Ermilovthen the overrun count is set to 175*5507a2aeSRuslan Ermilov.Brq Dv DELAYTIMER_MAX . 176*5507a2aeSRuslan ErmilovThe value returned by 177bb5eebe6SDavid Xu.Fn timer_getoverrun 178*5507a2aeSRuslan Ermilovapplies to the most recent expiration signal acceptance for the timer. 179*5507a2aeSRuslan ErmilovIf no 180bb5eebe6SDavid Xuexpiration signal has been delivered for the timer, the return value of 181bb5eebe6SDavid Xu.Fn timer_getoverrun 182bb5eebe6SDavid Xuis unspecified. 183bb5eebe6SDavid Xu.Sh RETURN VALUES 184bb5eebe6SDavid XuIf the 185bb5eebe6SDavid Xu.Fn timer_getoverrun 186*5507a2aeSRuslan Ermilovsystem call succeeds, it returns the timer expiration overrun count as explained 187bb5eebe6SDavid Xuabove. 188*5507a2aeSRuslan ErmilovOtherwise the value \-1 is returned, and the global variable 189*5507a2aeSRuslan Ermilov.Va errno 190*5507a2aeSRuslan Ermilovis set to indicate the error. 191bb5eebe6SDavid Xu.Pp 192*5507a2aeSRuslan Ermilov.Rv -std timer_gettime timer_settime 193bb5eebe6SDavid Xu.Sh ERRORS 194bb5eebe6SDavid XuThe 195bb5eebe6SDavid Xu.Fn timer_settime 196*5507a2aeSRuslan Ermilovsystem call 197bb5eebe6SDavid Xuwill fail if: 198bb5eebe6SDavid Xu.Bl -tag -width Er 199bb5eebe6SDavid Xu.It Bq Er EINVAL 200*5507a2aeSRuslan ErmilovA 201*5507a2aeSRuslan Ermilov.Fa value 202*5507a2aeSRuslan Ermilovstructure specified a nanosecond value less than zero or greater than 203*5507a2aeSRuslan Ermilovor equal to 1000 million, and the 204*5507a2aeSRuslan Ermilov.Va it_value 205*5507a2aeSRuslan Ermilovmember of that structure did not 206bb5eebe6SDavid Xuspecify zero seconds and nanoseconds. 207bb5eebe6SDavid Xu.El 208bb5eebe6SDavid Xu.Pp 209*5507a2aeSRuslan ErmilovThese system calls may fail if: 210bb5eebe6SDavid Xu.Bl -tag -width Er 211bb5eebe6SDavid Xu.It Bq Er EINVAL 212bb5eebe6SDavid XuThe 213bb5eebe6SDavid Xu.Fa timerid 214bb5eebe6SDavid Xuargument does not correspond to an ID returned by 215bb5eebe6SDavid Xu.Fn timer_create 216bb5eebe6SDavid Xubut not yet deleted by 217bb5eebe6SDavid Xu.Fn timer_delete . 218bb5eebe6SDavid Xu.El 219bb5eebe6SDavid Xu.Pp 220*5507a2aeSRuslan ErmilovThe 221*5507a2aeSRuslan Ermilov.Fn timer_settime 222*5507a2aeSRuslan Ermilovsystem call may fail if: 223bb5eebe6SDavid Xu.Bl -tag -width Er 224bb5eebe6SDavid Xu.It Bq Er EINVAL 225*5507a2aeSRuslan ErmilovThe 226*5507a2aeSRuslan Ermilov.Va it_interval 227*5507a2aeSRuslan Ermilovmember of 228*5507a2aeSRuslan Ermilov.Fa value 229*5507a2aeSRuslan Ermilovis not zero and the timer was created with 230*5507a2aeSRuslan Ermilovnotification by creation of a new thread 231*5507a2aeSRuslan Ermilov.Va ( sigev_sigev_notify 232*5507a2aeSRuslan Ermilovwas 233*5507a2aeSRuslan Ermilov.Dv SIGEV_THREAD ) 234bb5eebe6SDavid Xuand a fixed stack address has been set in the thread attribute pointed to by 235*5507a2aeSRuslan Ermilov.Va sigev_notify_attributes . 236bb5eebe6SDavid Xu.El 237bb5eebe6SDavid Xu.Pp 238bb5eebe6SDavid XuThe 239bb5eebe6SDavid Xu.Fn timer_gettime 240bb5eebe6SDavid Xuand 241bb5eebe6SDavid Xu.Fn timer_settime 242*5507a2aeSRuslan Ermilovsystem calls 243bb5eebe6SDavid Xumay fail if: 244bb5eebe6SDavid Xu.Bl -tag -width Er 245bb5eebe6SDavid Xu.It Bq Er EFAULT 246bb5eebe6SDavid XuAny arguments point outside the allocated address space or there is a 247bb5eebe6SDavid Xumemory protection fault. 248bb5eebe6SDavid Xu.El 249bb5eebe6SDavid Xu.Sh SEE ALSO 250bb5eebe6SDavid Xu.Xr clock_getres 2 , 251bb5eebe6SDavid Xu.Xr timer_create 2 252bb5eebe6SDavid Xu.Sh STANDARDS 253bb5eebe6SDavid XuThe 254bb5eebe6SDavid Xu.Fn timer_getoverrun , 255bb5eebe6SDavid Xu.Fn timer_gettime , 256bb5eebe6SDavid Xuand 257bb5eebe6SDavid Xu.Fn timer_settime 258*5507a2aeSRuslan Ermilovsystem calls conform to 259bb5eebe6SDavid Xu.St -p1003.1-96 . 260