This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH v2] Semaphores: add sem_clockwait GNU extension [BZ #14717]
On Mon, Dec 17, 2018 at 12:15:31AM +0000, Ben Hutchings wrote:
> 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).
Good catch. Will be fixed in v3.
The error values are also not in line with the proposal in [1] yet. I
will change the nptl/htl implementations to consistently set errno to
ENOTSUP if a particular clock is not supported.
I'll post it when the CLA is signed. Looks like my employer needs some
more time than anticipated... :/
Jan
[1] http://austingroupbugs.net/view.php?id=1216