1*8269e767SBrooks Davis.\" Copyright (c) 2005 David Xu <davidxu@FreeBSD.org> 2*8269e767SBrooks Davis.\" All rights reserved. 3*8269e767SBrooks Davis.\" 4*8269e767SBrooks Davis.\" Redistribution and use in source and binary forms, with or without 5*8269e767SBrooks Davis.\" modification, are permitted provided that the following conditions 6*8269e767SBrooks Davis.\" are met: 7*8269e767SBrooks Davis.\" 1. Redistributions of source code must retain the above copyright 8*8269e767SBrooks Davis.\" notice(s), this list of conditions and the following disclaimer as 9*8269e767SBrooks Davis.\" the first lines of this file unmodified other than the possible 10*8269e767SBrooks Davis.\" addition of one or more copyright notices. 11*8269e767SBrooks Davis.\" 2. Redistributions in binary form must reproduce the above copyright 12*8269e767SBrooks Davis.\" notice(s), this list of conditions and the following disclaimer in 13*8269e767SBrooks Davis.\" the documentation and/or other materials provided with the 14*8269e767SBrooks Davis.\" distribution. 15*8269e767SBrooks Davis.\" 16*8269e767SBrooks Davis.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY 17*8269e767SBrooks Davis.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18*8269e767SBrooks Davis.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19*8269e767SBrooks Davis.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE 20*8269e767SBrooks Davis.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21*8269e767SBrooks Davis.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22*8269e767SBrooks Davis.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 23*8269e767SBrooks Davis.\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24*8269e767SBrooks Davis.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 25*8269e767SBrooks Davis.\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 26*8269e767SBrooks Davis.\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27*8269e767SBrooks Davis.\" 28*8269e767SBrooks Davis.Dd September 11, 2000 29*8269e767SBrooks Davis.Dt TIMER_SETTIME 2 30*8269e767SBrooks Davis.Os 31*8269e767SBrooks Davis.Sh NAME 32*8269e767SBrooks Davis.Nm timer_getoverrun , 33*8269e767SBrooks Davis.Nm timer_gettime , 34*8269e767SBrooks Davis.Nm timer_settime 35*8269e767SBrooks Davis.Nd "per-process timers (REALTIME)" 36*8269e767SBrooks Davis.Sh LIBRARY 37*8269e767SBrooks Davis.Lb librt 38*8269e767SBrooks Davis.Sh SYNOPSIS 39*8269e767SBrooks Davis.In time.h 40*8269e767SBrooks Davis.Ft int 41*8269e767SBrooks Davis.Fn timer_getoverrun "timer_t timerid" 42*8269e767SBrooks Davis.Ft int 43*8269e767SBrooks Davis.Fn timer_gettime "timer_t timerid" "struct itimerspec *value" 44*8269e767SBrooks Davis.Ft int 45*8269e767SBrooks Davis.Fo timer_settime 46*8269e767SBrooks Davis.Fa "timer_t timerid" "int flags" "const struct itimerspec *restrict value" 47*8269e767SBrooks Davis.Fa "struct itimerspec *restrict ovalue" 48*8269e767SBrooks Davis.Fc 49*8269e767SBrooks Davis.Sh DESCRIPTION 50*8269e767SBrooks DavisThe 51*8269e767SBrooks Davis.Fn timer_gettime 52*8269e767SBrooks Davissystem call stores the amount of time until the specified timer, 53*8269e767SBrooks Davis.Fa timerid , 54*8269e767SBrooks Davisexpires and the reload value of the timer into the space pointed to by the 55*8269e767SBrooks Davis.Fa value 56*8269e767SBrooks Davisargument. 57*8269e767SBrooks DavisThe 58*8269e767SBrooks Davis.Va it_value 59*8269e767SBrooks Davismember of this structure contains the amount of time 60*8269e767SBrooks Davisbefore the timer expires, or zero if the timer is disarmed. 61*8269e767SBrooks DavisThis value is 62*8269e767SBrooks Davisreturned as the interval until timer expiration, even if the timer was armed 63*8269e767SBrooks Daviswith absolute time. 64*8269e767SBrooks DavisThe 65*8269e767SBrooks Davis.Va it_interval 66*8269e767SBrooks Davismember of 67*8269e767SBrooks Davis.Fa value 68*8269e767SBrooks Daviscontains the reload 69*8269e767SBrooks Davisvalue last set by 70*8269e767SBrooks Davis.Fn timer_settime . 71*8269e767SBrooks Davis.Pp 72*8269e767SBrooks DavisThe 73*8269e767SBrooks Davis.Fn timer_settime 74*8269e767SBrooks Davissystem call sets the time until the next expiration of the timer specified 75*8269e767SBrooks Davisby 76*8269e767SBrooks Davis.Fa timerid 77*8269e767SBrooks Davisfrom the 78*8269e767SBrooks Davis.Va it_value 79*8269e767SBrooks Davismember of the 80*8269e767SBrooks Davis.Fa value 81*8269e767SBrooks Davisargument and arms the timer if the 82*8269e767SBrooks Davis.Va it_value 83*8269e767SBrooks Davismember of 84*8269e767SBrooks Davis.Fa value 85*8269e767SBrooks Davisis non-zero. 86*8269e767SBrooks DavisIf the specified timer was already 87*8269e767SBrooks Davisarmed when 88*8269e767SBrooks Davis.Fn timer_settime 89*8269e767SBrooks Davisis called, this call resets the time until next expiration to the value 90*8269e767SBrooks Davisspecified. 91*8269e767SBrooks DavisIf the 92*8269e767SBrooks Davis.Va it_value 93*8269e767SBrooks Davismember of 94*8269e767SBrooks Davis.Fa value 95*8269e767SBrooks Davisis zero, the timer is disarmed. 96*8269e767SBrooks DavisIf the timer is disarmed, then pending signal is removed. 97*8269e767SBrooks Davis.Pp 98*8269e767SBrooks DavisIf the flag 99*8269e767SBrooks Davis.Dv TIMER_ABSTIME 100*8269e767SBrooks Davisis not set in the argument 101*8269e767SBrooks Davis.Fa flags , 102*8269e767SBrooks Davis.Fn timer_settime 103*8269e767SBrooks Davisbehaves as if the time until next expiration is set to 104*8269e767SBrooks Davisbe equal to the interval specified by the 105*8269e767SBrooks Davis.Va it_value 106*8269e767SBrooks Davismember of 107*8269e767SBrooks Davis.Fa value . 108*8269e767SBrooks DavisThat is, 109*8269e767SBrooks Davisthe timer expires in 110*8269e767SBrooks Davis.Va it_value 111*8269e767SBrooks Davisnanoseconds from when the call is made. 112*8269e767SBrooks DavisIf the flag 113*8269e767SBrooks Davis.Dv TIMER_ABSTIME 114*8269e767SBrooks Davisis set in the argument 115*8269e767SBrooks Davis.Fa flags , 116*8269e767SBrooks Davis.Fn timer_settime 117*8269e767SBrooks Davisbehaves as if the time until next expiration is set to be equal to the 118*8269e767SBrooks Davisdifference between the absolute time specified by the it_value member of 119*8269e767SBrooks Davisvalue and the current value of the clock associated with 120*8269e767SBrooks Davis.Fa timerid . 121*8269e767SBrooks DavisThat is, the timer expires when the clock reaches the value specified by the 122*8269e767SBrooks Davis.Va it_value 123*8269e767SBrooks Davismember of 124*8269e767SBrooks Davis.Fa value . 125*8269e767SBrooks DavisIf the specified time has already passed, the 126*8269e767SBrooks Davissystem call succeeds and the expiration notification is made. 127*8269e767SBrooks Davis.Pp 128*8269e767SBrooks DavisThe reload value of the timer is set to the value specified by the 129*8269e767SBrooks Davis.Va it_interval 130*8269e767SBrooks Davismember of 131*8269e767SBrooks Davis.Fa value . 132*8269e767SBrooks DavisWhen a timer is armed with a non-zero 133*8269e767SBrooks Davis.Va it_interval , 134*8269e767SBrooks Davisa periodic 135*8269e767SBrooks Davis(or repetitive) timer is specified. 136*8269e767SBrooks Davis.Pp 137*8269e767SBrooks DavisTime values that are between two consecutive non-negative integer multiples of 138*8269e767SBrooks Davisthe resolution of the specified timer are rounded up to the larger multiple of 139*8269e767SBrooks Davisthe resolution. 140*8269e767SBrooks DavisQuantization error will not cause the timer to expire earlier 141*8269e767SBrooks Davisthan the rounded time value. 142*8269e767SBrooks Davis.Pp 143*8269e767SBrooks DavisIf the argument 144*8269e767SBrooks Davis.Fa ovalue 145*8269e767SBrooks Davisis not 146*8269e767SBrooks Davis.Dv NULL , 147*8269e767SBrooks Davisthe 148*8269e767SBrooks Davis.Fn timer_settime 149*8269e767SBrooks Davissystem call stores, in the location referenced by 150*8269e767SBrooks Davis.Fa ovalue , 151*8269e767SBrooks Davisa value representing 152*8269e767SBrooks Davisthe previous amount of time before the timer would have expired, or zero if the 153*8269e767SBrooks Davistimer was disarmed, together with the previous timer reload value. 154*8269e767SBrooks DavisTimers do not 155*8269e767SBrooks Davisexpire before their scheduled time. 156*8269e767SBrooks Davis.Pp 157*8269e767SBrooks DavisOnly a single signal is queued to the process for a given timer at any point in 158*8269e767SBrooks Davistime. 159*8269e767SBrooks DavisWhen a timer for which a signal is still pending expires, no signal is 160*8269e767SBrooks Davisqueued, and a timer overrun will occur. 161*8269e767SBrooks DavisWhen a timer expiration signal is 162*8269e767SBrooks Davisaccepted by a process, the 163*8269e767SBrooks Davis.Fn timer_getoverrun 164*8269e767SBrooks Davissystem call returns the timer expiration overrun count for the specified timer. 165*8269e767SBrooks DavisThe overrun count returned contains the number of extra timer expirations that 166*8269e767SBrooks Davisoccurred between the time the signal was generated (queued) and when it was 167*8269e767SBrooks Davisaccepted, up to but not including an maximum of 168*8269e767SBrooks Davis.Brq Dv DELAYTIMER_MAX . 169*8269e767SBrooks DavisIf the number of 170*8269e767SBrooks Davissuch extra expirations is greater than or equal to 171*8269e767SBrooks Davis.Brq Dv DELAYTIMER_MAX , 172*8269e767SBrooks Davisthen the overrun count is set to 173*8269e767SBrooks Davis.Brq Dv DELAYTIMER_MAX . 174*8269e767SBrooks DavisThe value returned by 175*8269e767SBrooks Davis.Fn timer_getoverrun 176*8269e767SBrooks Davisapplies to the most recent expiration signal acceptance for the timer. 177*8269e767SBrooks DavisIf no 178*8269e767SBrooks Davisexpiration signal has been delivered for the timer, the return value of 179*8269e767SBrooks Davis.Fn timer_getoverrun 180*8269e767SBrooks Davisis unspecified. 181*8269e767SBrooks Davis.Sh RETURN VALUES 182*8269e767SBrooks DavisIf the 183*8269e767SBrooks Davis.Fn timer_getoverrun 184*8269e767SBrooks Davissystem call succeeds, it returns the timer expiration overrun count as explained 185*8269e767SBrooks Davisabove. 186*8269e767SBrooks DavisOtherwise the value \-1 is returned, and the global variable 187*8269e767SBrooks Davis.Va errno 188*8269e767SBrooks Davisis set to indicate the error. 189*8269e767SBrooks Davis.Pp 190*8269e767SBrooks Davis.Rv -std timer_gettime timer_settime 191*8269e767SBrooks Davis.Sh ERRORS 192*8269e767SBrooks DavisThe 193*8269e767SBrooks Davis.Fn timer_settime 194*8269e767SBrooks Davissystem call 195*8269e767SBrooks Daviswill fail if: 196*8269e767SBrooks Davis.Bl -tag -width Er 197*8269e767SBrooks Davis.It Bq Er EINVAL 198*8269e767SBrooks DavisA 199*8269e767SBrooks Davis.Fa value 200*8269e767SBrooks Davisstructure specified a nanosecond value less than zero or greater than 201*8269e767SBrooks Davisor equal to 1000 million, and the 202*8269e767SBrooks Davis.Va it_value 203*8269e767SBrooks Davismember of that structure did not 204*8269e767SBrooks Davisspecify zero seconds and nanoseconds. 205*8269e767SBrooks Davis.El 206*8269e767SBrooks Davis.Pp 207*8269e767SBrooks DavisThese system calls may fail if: 208*8269e767SBrooks Davis.Bl -tag -width Er 209*8269e767SBrooks Davis.It Bq Er EINVAL 210*8269e767SBrooks DavisThe 211*8269e767SBrooks Davis.Fa timerid 212*8269e767SBrooks Davisargument does not correspond to an ID returned by 213*8269e767SBrooks Davis.Fn timer_create 214*8269e767SBrooks Davisbut not yet deleted by 215*8269e767SBrooks Davis.Fn timer_delete . 216*8269e767SBrooks Davis.El 217*8269e767SBrooks Davis.Pp 218*8269e767SBrooks DavisThe 219*8269e767SBrooks Davis.Fn timer_settime 220*8269e767SBrooks Davissystem call may fail if: 221*8269e767SBrooks Davis.Bl -tag -width Er 222*8269e767SBrooks Davis.It Bq Er EINVAL 223*8269e767SBrooks DavisThe 224*8269e767SBrooks Davis.Va it_interval 225*8269e767SBrooks Davismember of 226*8269e767SBrooks Davis.Fa value 227*8269e767SBrooks Davisis not zero and the timer was created with 228*8269e767SBrooks Davisnotification by creation of a new thread 229*8269e767SBrooks Davis.Va ( sigev_sigev_notify 230*8269e767SBrooks Daviswas 231*8269e767SBrooks Davis.Dv SIGEV_THREAD ) 232*8269e767SBrooks Davisand a fixed stack address has been set in the thread attribute pointed to by 233*8269e767SBrooks Davis.Va sigev_notify_attributes . 234*8269e767SBrooks Davis.El 235*8269e767SBrooks Davis.Pp 236*8269e767SBrooks DavisThe 237*8269e767SBrooks Davis.Fn timer_gettime 238*8269e767SBrooks Davisand 239*8269e767SBrooks Davis.Fn timer_settime 240*8269e767SBrooks Davissystem calls 241*8269e767SBrooks Davismay fail if: 242*8269e767SBrooks Davis.Bl -tag -width Er 243*8269e767SBrooks Davis.It Bq Er EFAULT 244*8269e767SBrooks DavisAny arguments point outside the allocated address space or there is a 245*8269e767SBrooks Davismemory protection fault. 246*8269e767SBrooks Davis.El 247*8269e767SBrooks Davis.Sh SEE ALSO 248*8269e767SBrooks Davis.Xr clock_getres 2 , 249*8269e767SBrooks Davis.Xr timer_create 2 , 250*8269e767SBrooks Davis.Xr siginfo 3 251*8269e767SBrooks Davis.Sh STANDARDS 252*8269e767SBrooks DavisThe 253*8269e767SBrooks Davis.Fn timer_getoverrun , 254*8269e767SBrooks Davis.Fn timer_gettime , 255*8269e767SBrooks Davisand 256*8269e767SBrooks Davis.Fn timer_settime 257*8269e767SBrooks Davissystem calls conform to 258*8269e767SBrooks Davis.St -p1003.1-2004 . 259*8269e767SBrooks Davis.Sh HISTORY 260*8269e767SBrooks DavisSupport for 261*8269e767SBrooks Davis.Tn POSIX 262*8269e767SBrooks Davisper-process timer first appeared in 263*8269e767SBrooks Davis.Fx 7.0 . 264