162486687SUlrich Spörlein.\" Copyright (c) 2008, David Xu <davidxu@FreeBSD.org> 21dd273dfSDavid Xu.\" All rights reserved. 31dd273dfSDavid Xu.\" 41dd273dfSDavid Xu.\" Redistribution and use in source and binary forms, with or without 51dd273dfSDavid Xu.\" modification, are permitted provided that the following conditions 61dd273dfSDavid Xu.\" are met: 71dd273dfSDavid Xu.\" 1. Redistributions of source code must retain the above copyright 81dd273dfSDavid Xu.\" notice, this list of conditions and the following disclaimer. 91dd273dfSDavid Xu.\" 2. Redistributions in binary form must reproduce the above copyright 101dd273dfSDavid Xu.\" notice, this list of conditions and the following disclaimer in the 111dd273dfSDavid Xu.\" documentation and/or other materials provided with the distribution. 121dd273dfSDavid Xu.\" 131dd273dfSDavid Xu.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 141dd273dfSDavid Xu.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 151dd273dfSDavid Xu.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 161dd273dfSDavid Xu.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 171dd273dfSDavid Xu.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 181dd273dfSDavid Xu.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 191dd273dfSDavid Xu.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 201dd273dfSDavid Xu.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 211dd273dfSDavid Xu.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 221dd273dfSDavid Xu.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 231dd273dfSDavid Xu.\" SUCH DAMAGE. 241dd273dfSDavid Xu.\" 251dd273dfSDavid Xu.\" Portions of this text are reprinted and reproduced in electronic form 261dd273dfSDavid Xu.\" from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- 271dd273dfSDavid Xu.\" Portable Operating System Interface (POSIX), The Open Group Base 281dd273dfSDavid Xu.\" Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of 291dd273dfSDavid Xu.\" Electrical and Electronics Engineers, Inc and The Open Group. In the 301dd273dfSDavid Xu.\" event of any discrepancy between this version and the original IEEE and 311dd273dfSDavid Xu.\" The Open Group Standard, the original IEEE and The Open Group Standard is 321dd273dfSDavid Xu.\" the referee document. The original Standard can be obtained online at 331dd273dfSDavid Xu.\" http://www.opengroup.org/unix/online.html. 341dd273dfSDavid Xu.\" 35*4adb4080SGlen Barber.Dd May 24, 2017 361dd273dfSDavid Xu.Dt SEM_TIMEDWAIT 3 371dd273dfSDavid Xu.Os 381dd273dfSDavid Xu.Sh NAME 39b215ceaaSEric van Gyzen.Nm sem_timedwait , 40b215ceaaSEric van Gyzen.Nm sem_clockwait_np 411dd273dfSDavid Xu.Nd "lock a semaphore" 421dd273dfSDavid Xu.Sh LIBRARY 430de6c9d6SKevin Lo.Lb libc 441dd273dfSDavid Xu.Sh SYNOPSIS 451dd273dfSDavid Xu.In semaphore.h 4681027fa5SEric van Gyzen.In time.h 471dd273dfSDavid Xu.Ft int 480de6c9d6SKevin Lo.Fn sem_timedwait "sem_t * restrict sem" "const struct timespec * restrict abs_timeout" 49b215ceaaSEric van Gyzen.Ft int 50b215ceaaSEric van Gyzen.Fn sem_clockwait_np "sem_t * restrict sem" "clockid_t clock_id" "int flags" "const struct timespec * rqtp" "struct timespec * rmtp" 511dd273dfSDavid Xu.Sh DESCRIPTION 521dd273dfSDavid XuThe 531dd273dfSDavid Xu.Fn sem_timedwait 541dd273dfSDavid Xufunction locks the semaphore referenced by 551dd273dfSDavid Xu.Fa sem , 561dd273dfSDavid Xuas in the 571dd273dfSDavid Xu.Xr sem_wait 3 581dd273dfSDavid Xufunction. 591dd273dfSDavid XuHowever, if the semaphore cannot be locked without waiting for 601dd273dfSDavid Xuanother process or thread to unlock the semaphore by performing 611dd273dfSDavid Xua 621dd273dfSDavid Xu.Xr sem_post 3 631dd273dfSDavid Xufunction, this wait will be terminated when the specified timeout expires. 641dd273dfSDavid Xu.Pp 651dd273dfSDavid XuThe timeout will expire when the absolute time specified by 661dd273dfSDavid Xu.Fa abs_timeout 671dd273dfSDavid Xupasses, as measured by the clock on which timeouts are based (that is, 681dd273dfSDavid Xuwhen the value of that clock equals or exceeds 691dd273dfSDavid Xu.Fa abs_timeout ) , 701dd273dfSDavid Xuor if the 711dd273dfSDavid Xuabsolute time specified by 721dd273dfSDavid Xu.Fa abs_timeout 731dd273dfSDavid Xuhas already been passed at the time of the call. 741dd273dfSDavid Xu.Pp 751dd273dfSDavid XuNote that the timeout is based on the 761dd273dfSDavid Xu.Dv CLOCK_REALTIME 771dd273dfSDavid Xuclock. 781dd273dfSDavid Xu.Pp 791dd273dfSDavid XuThe validity of the 801dd273dfSDavid Xu.Fa abs_timeout 811dd273dfSDavid Xuis not checked if the semaphore can be locked immediately. 82b215ceaaSEric van Gyzen.Pp 831dd273dfSDavid XuThe 84b215ceaaSEric van Gyzen.Fn sem_clockwait_np 85b215ceaaSEric van Gyzenfunction is a more flexible variant of 86b215ceaaSEric van Gyzen.Fn sem_timedwait . 87b215ceaaSEric van GyzenThe 88b215ceaaSEric van Gyzen.Fa clock_id 89b215ceaaSEric van Gyzenparameter specifies the reference clock. 90b215ceaaSEric van GyzenIf the 91b215ceaaSEric van Gyzen.Fa flags 92b215ceaaSEric van Gyzenparameter contains 93b215ceaaSEric van Gyzen.Dv TIMER_ABSTIME , 94b215ceaaSEric van Gyzenthen the requested timeout 95b215ceaaSEric van Gyzen.Pq Fa rqtp 96b215ceaaSEric van Gyzenis an absolute timeout; otherwise, 97b215ceaaSEric van Gyzenthe timeout is relative. 98b215ceaaSEric van GyzenIf this function fails with 99b215ceaaSEric van Gyzen.Er EINTR 100b215ceaaSEric van Gyzenand the timeout is relative, 101b215ceaaSEric van Gyzena non-NULL 102b215ceaaSEric van Gyzen.Fa rmtp 103b215ceaaSEric van Gyzenwill be updated to contain the amount of time remaining in the interval 104b215ceaaSEric van Gyzen.Po 105b215ceaaSEric van Gyzenthe requested time minus the time actually slept 106b215ceaaSEric van Gyzen.Pc . 107b215ceaaSEric van GyzenAn absolute timeout has no effect on 108b215ceaaSEric van Gyzen.Fa rmtp . 109b215ceaaSEric van GyzenA single structure can be used for both 110b215ceaaSEric van Gyzen.Fa rqtp 111b215ceaaSEric van Gyzenand 112b215ceaaSEric van Gyzen.Fa rmtp . 113b215ceaaSEric van Gyzen.Sh RETURN VALUES 114b215ceaaSEric van GyzenThese 115b215ceaaSEric van Gyzenfunctions return zero if the calling process successfully performed the 1161dd273dfSDavid Xusemaphore lock operation on the semaphore designated by 1171dd273dfSDavid Xu.Fa sem . 1181dd273dfSDavid XuIf the call was unsuccessful, the state of the semaphore is unchanged, 1191dd273dfSDavid Xuand the function returns a value of \-1 and sets the global variable 1201dd273dfSDavid Xu.Va errno 1211dd273dfSDavid Xuto indicate the error. 1221dd273dfSDavid Xu.Sh ERRORS 123b215ceaaSEric van GyzenThese functions will fail if: 1241dd273dfSDavid Xu.Bl -tag -width Er 1251dd273dfSDavid Xu.It Bq Er EINVAL 1261dd273dfSDavid XuThe 1271dd273dfSDavid Xu.Fa sem 1281dd273dfSDavid Xuargument does not refer to a valid semaphore, or the process or thread would 1291dd273dfSDavid Xuhave blocked, and the 1301dd273dfSDavid Xu.Fa abs_timeout 1311dd273dfSDavid Xuparameter specified a nanoseconds field value less than zero or greater than 1321dd273dfSDavid Xuor equal to 1000 million. 1331dd273dfSDavid Xu.It Bq Er ETIMEDOUT 1341dd273dfSDavid XuThe semaphore could not be locked before the specified timeout expired. 1351dd273dfSDavid Xu.It Bq Er EINTR 1361dd273dfSDavid XuA signal interrupted this function. 1371dd273dfSDavid Xu.El 1381dd273dfSDavid Xu.Sh SEE ALSO 1391dd273dfSDavid Xu.Xr sem_post 3 , 1401dd273dfSDavid Xu.Xr sem_trywait 3 , 14115096da3SJohn Baldwin.Xr sem_wait 3 1421dd273dfSDavid Xu.Sh STANDARDS 1431dd273dfSDavid XuThe 1441dd273dfSDavid Xu.Fn sem_timedwait 1451dd273dfSDavid Xufunction conforms to 1461dd273dfSDavid Xu.St -p1003.1-2004 . 147b215ceaaSEric van GyzenThe 148b215ceaaSEric van Gyzen.Fn sem_clockwait_np 149b215ceaaSEric van Gyzenfunction is not specified by any standard; 150b215ceaaSEric van Gyzenit exists only on 151b215ceaaSEric van Gyzen.Fx 152b215ceaaSEric van Gyzenat the time of this writing. 1531dd273dfSDavid Xu.Sh HISTORY 154b215ceaaSEric van GyzenThe 155b215ceaaSEric van Gyzen.Fn sem_timedwait 156b215ceaaSEric van Gyzenfunction first appeared in 1571dd273dfSDavid Xu.Fx 5.0 . 158b215ceaaSEric van GyzenThe 159b215ceaaSEric van Gyzen.Fn sem_clockwait_np 160b215ceaaSEric van Gyzenfunction first appeared in 161*4adb4080SGlen Barber.Fx 11.1 . 162