[PATCH v2] Semaphores: add sem_clockwait GNU extension [BZ #14717]
Ben Hutchings
ben.hutchings@codethink.co.uk
Mon Dec 17 06:38:00 GMT 2018
On Fri, 2018-12-14 at 22:20 +0100, Jan Klötzke wrote:
> As defined by POSIX.1-2001 the 'abstime' timeout of  sem_timedwait()
> shall be based on CLOCK_REALTIME. This has the unpleasant effect that
> application timeouts are affected by system clock adjustments.
>
> The added sem_clockwait() function behaves just like sem_timedwait() but
> lets the user specify the clock against which the timeout is measured.
> The implementation is based on [1] which covers all functions that take an
> absolute struct timespec timeout.
[...]
> --- /dev/null
> +++ b/nptl/sem_clockwait.c
> @@ -0,0 +1,52 @@
[...]
> +int
> +sem_clockwait (sem_t *sem, clockid_t clock_id, const struct timespec *abstime)
> +{
> + if (__glibc_unlikely (abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000))
> + {
> + __set_errno (EINVAL);
> + return -1;
> + }
> +
> + if (__glibc_unlikely (clock_id != CLOCK_MONOTONIC
> + && clock_id != CLOCK_REALTIME))
> + {
> + __set_errno (EINVAL);
> + return -1;
> + }
> +
> + /* If we do not support waiting using CLOCK_MONOTONIC, return an error. */
> + if (clock_id == CLOCK_MONOTONIC
> + && !futex_supports_exact_relative_timeouts())
> + return ENOTSUP;
[...]
Returning an error code here is inconsistent with sem_timedwait() (and
even with the other error cases).
Ben.
--
Ben Hutchings, Software Developer  Codethink Ltd
https://www.codethink.co.uk/ Dale House, 35 Dale Street
Manchester, M1 2HF, United Kingdom
More information about the Libc-alpha
mailing list