]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
nptl: Add POSIX-proposed sem_clockwait
authorMike Crowe <mac@mcrowe.com>
Fri, 21 Jun 2019 15:57:41 +0000 (15:57 +0000)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Fri, 12 Jul 2019 13:36:23 +0000 (13:36 +0000)
Add:

 int sem_clockwait (sem_t *sem, clockid_t clock, const struct timespec
*abstime)

which behaves just like sem_timedwait, but measures abstime against the
specified clock. Currently supports CLOCK_REALTIME and CLOCK_MONOTONIC
and sets errno == EINVAL if any other clock is specified.

* nptl/sem_waitcommon.c (do_futex_wait, __new_sem_wait_slow): Add
clockid parameters to indicate the clock which abstime should be
measured against.
* nptl/sem_timedwait.c (sem_timedwait), nptl/sem_wait.c
(__new_sem_wait): Pass CLOCK_REALTIME as clockid to
__new_sem_wait_slow.
* nptl/sem_clockwait.c: New file to implement sem_clockwait based
on sem_timedwait.c.
* nptl/Makefile: Add sem_clockwait.c source file. Add CFLAGS for
sem_clockwait.c to match those used for sem_timedwait.c.
* sysdeps/pthread/semaphore.h: Add sem_clockwait.
* nptl/Versions (GLIBC_2.30): Likewise.
* sysdeps/unix/sysv/linux/aarch64/libpthread.abilist (GLIBC_2.30): Likewise.
* sysdeps/unix/sysv/linux/alpha/libpthread.abilist (GLIBC_2.30): Likewise.
* sysdeps/unix/sysv/linux/arm/libpthread.abilist (GLIBC_2.30): Likewise.
* sysdeps/unix/sysv/linux/csky/libpthread.abilist (GLIBC_2.30): Likewise.
* sysdeps/unix/sysv/linux/hppa/libpthread.abilist (GLIBC_2.30): Likewise.
* sysdeps/unix/sysv/linux/i386/libpthread.abilist (GLIBC_2.30): Likewise.
* sysdeps/unix/sysv/linux/ia64/libpthread.abilist (GLIBC_2.30): Likewise.
* sysdeps/unix/sysv/linux/m68k/coldfire/libpthread.abilist
(GLIBC_2.30): Likewise.
* sysdeps/unix/sysv/linux/m68k/m680x0/libpthread.abilist
(GLIBC_2.30): Likewise.
* sysdeps/unix/sysv/linux/microblaze/libpthread.abilist
(GLIBC_2.30): Likewise.
* sysdeps/unix/sysv/linux/mips/mips32/libpthread.abilist
(GLIBC_2.30): Likewise.
* sysdeps/unix/sysv/linux/mips/mips64/libpthread.abilist
(GLIBC_2.30): Likewise.
* sysdeps/unix/sysv/linux/nios2/libpthread.abilist (GLIBC_2.30): Likewise.
* sysdeps/unix/sysv/linux/powerpc/powerpc32/libpthread.abilist
(GLIBC_2.30): Likewise.
* sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libpthread.abilist
(GLIBC_2.30): Likewise.
* sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libpthread.abilist
(GLIBC_2.30): Likewise.
* sysdeps/unix/sysv/linux/riscv/rv64/libpthread.abilist
(GLIBC_2.30): Likewise.
* sysdeps/unix/sysv/linux/s390/s390-32/libpthread.abilist
(GLIBC_2.30): Likewise.
* sysdeps/unix/sysv/linux/s390/s390-64/libpthread.abilist
(GLIBC_2.30): Likewise.
* sysdeps/unix/sysv/linux/sh/libpthread.abilist (GLIBC_2.30): Likewise.
* sysdeps/unix/sysv/linux/sparc/sparc32/libpthread.abilist
(GLIBC_2.30): Likewise.
* sysdeps/unix/sysv/linux/sparc/sparc64/libpthread.abilist
(GLIBC_2.30): Likewise.
* sysdeps/unix/sysv/linux/x86_64/64/libpthread.abilist
(GLIBC_2.30): Likewise.
* sysdeps/unix/sysv/linux/x86_64/x32/libpthread.abilist
(GLIBC_2.30): Likewise.
* nptl/tst-sem17.c: Add new test for passing invalid clock to
sem_clockwait.
* nptl/tst-sem13.c, nptl/tst-sem5.c: Modify existing sem_timedwait
tests to also test sem_clockwait.
* manual/threads.texi: Document sem_clockwait.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
36 files changed:
ChangeLog
manual/threads.texi
nptl/Makefile
nptl/Versions
nptl/sem_clockwait.c [new file with mode: 0644]
nptl/sem_timedwait.c
nptl/sem_wait.c
nptl/sem_waitcommon.c
nptl/tst-sem13.c
nptl/tst-sem17.c [new file with mode: 0644]
nptl/tst-sem5.c
sysdeps/pthread/semaphore.h
sysdeps/unix/sysv/linux/aarch64/libpthread.abilist
sysdeps/unix/sysv/linux/alpha/libpthread.abilist
sysdeps/unix/sysv/linux/arm/libpthread.abilist
sysdeps/unix/sysv/linux/csky/libpthread.abilist
sysdeps/unix/sysv/linux/hppa/libpthread.abilist
sysdeps/unix/sysv/linux/i386/libpthread.abilist
sysdeps/unix/sysv/linux/ia64/libpthread.abilist
sysdeps/unix/sysv/linux/m68k/coldfire/libpthread.abilist
sysdeps/unix/sysv/linux/m68k/m680x0/libpthread.abilist
sysdeps/unix/sysv/linux/microblaze/libpthread.abilist
sysdeps/unix/sysv/linux/mips/mips32/libpthread.abilist
sysdeps/unix/sysv/linux/mips/mips64/libpthread.abilist
sysdeps/unix/sysv/linux/nios2/libpthread.abilist
sysdeps/unix/sysv/linux/powerpc/powerpc32/libpthread.abilist
sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libpthread.abilist
sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libpthread.abilist
sysdeps/unix/sysv/linux/riscv/rv64/libpthread.abilist
sysdeps/unix/sysv/linux/s390/s390-32/libpthread.abilist
sysdeps/unix/sysv/linux/s390/s390-64/libpthread.abilist
sysdeps/unix/sysv/linux/sh/libpthread.abilist
sysdeps/unix/sysv/linux/sparc/sparc32/libpthread.abilist
sysdeps/unix/sysv/linux/sparc/sparc64/libpthread.abilist
sysdeps/unix/sysv/linux/x86_64/64/libpthread.abilist
sysdeps/unix/sysv/linux/x86_64/x32/libpthread.abilist

index 11cabf28d6aa6d89565f3f710eb2efcbcc765ae7..d52545347b9f6500baf62c0f7eee71e916690124 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,64 @@
 2019-07-12  Mike Crowe  <mac@mcrowe.com>
 
+       nptl: Add POSIX-proposed sem_clockwait which behaves just like
+       sem_timedwait, but measures abstime against the specified clock.
+       * nptl/sem_waitcommon.c (do_futex_wait, __new_sem_wait_slow): Add
+       clockid parameters to indicate the clock which abstime should be
+       measured against.
+       * nptl/sem_timedwait.c (sem_timedwait), nptl/sem_wait.c
+       (__new_sem_wait): Pass CLOCK_REALTIME as clockid to
+       __new_sem_wait_slow.
+       * nptl/sem_clockwait.c: New file to implement sem_clockwait based
+       on sem_timedwait.c.
+       * nptl/Makefile: Add sem_clockwait.c source file. Add CFLAGS for
+       sem_clockwait.c to match those used for sem_timedwait.c.
+       * sysdeps/pthread/semaphore.h: Add sem_clockwait.
+       * nptl/Versions (GLIBC_2.30): Likewise.
+       * sysdeps/unix/sysv/linux/aarch64/libpthread.abilist (GLIBC_2.30): Likewise.
+       * sysdeps/unix/sysv/linux/alpha/libpthread.abilist (GLIBC_2.30): Likewise.
+       * sysdeps/unix/sysv/linux/arm/libpthread.abilist (GLIBC_2.30): Likewise.
+       * sysdeps/unix/sysv/linux/csky/libpthread.abilist (GLIBC_2.30): Likewise.
+       * sysdeps/unix/sysv/linux/hppa/libpthread.abilist (GLIBC_2.30): Likewise.
+       * sysdeps/unix/sysv/linux/i386/libpthread.abilist (GLIBC_2.30): Likewise.
+       * sysdeps/unix/sysv/linux/ia64/libpthread.abilist (GLIBC_2.30): Likewise.
+       * sysdeps/unix/sysv/linux/m68k/coldfire/libpthread.abilist
+       (GLIBC_2.30): Likewise.
+       * sysdeps/unix/sysv/linux/m68k/m680x0/libpthread.abilist
+       (GLIBC_2.30): Likewise.
+       * sysdeps/unix/sysv/linux/microblaze/libpthread.abilist
+       (GLIBC_2.30): Likewise.
+       * sysdeps/unix/sysv/linux/mips/mips32/libpthread.abilist
+       (GLIBC_2.30): Likewise.
+       * sysdeps/unix/sysv/linux/mips/mips64/libpthread.abilist
+       (GLIBC_2.30): Likewise.
+       * sysdeps/unix/sysv/linux/nios2/libpthread.abilist (GLIBC_2.30): Likewise.
+       * sysdeps/unix/sysv/linux/powerpc/powerpc32/libpthread.abilist
+       (GLIBC_2.30): Likewise.
+       * sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libpthread.abilist
+       (GLIBC_2.30): Likewise.
+       * sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libpthread.abilist
+       (GLIBC_2.30): Likewise.
+       * sysdeps/unix/sysv/linux/riscv/rv64/libpthread.abilist
+       (GLIBC_2.30): Likewise.
+       * sysdeps/unix/sysv/linux/s390/s390-32/libpthread.abilist
+       (GLIBC_2.30): Likewise.
+       * sysdeps/unix/sysv/linux/s390/s390-64/libpthread.abilist
+       (GLIBC_2.30): Likewise.
+       * sysdeps/unix/sysv/linux/sh/libpthread.abilist (GLIBC_2.30): Likewise.
+       * sysdeps/unix/sysv/linux/sparc/sparc32/libpthread.abilist
+       (GLIBC_2.30): Likewise.
+       * sysdeps/unix/sysv/linux/sparc/sparc64/libpthread.abilist
+       (GLIBC_2.30): Likewise.
+       * sysdeps/unix/sysv/linux/x86_64/64/libpthread.abilist
+       (GLIBC_2.30): Likewise.
+       * sysdeps/unix/sysv/linux/x86_64/x32/libpthread.abilist
+       (GLIBC_2.30): Likewise.
+       * nptl/tst-sem17.c: Add new test for passing invalid clock to
+       sem_clockwait.
+       * nptl/tst-sem13.c, nptl/tst-sem5.c: Modify existing sem_timedwait
+       tests to also test sem_clockwait.
+       * manual/threads.texi: Document sem_clockwait.
+
        nptl: Add clockid parameter to futex timed wait calls
        * sysdeps/nptl/lowlevellock-futex.h,
        sysdeps/unix/sysv/linux/lowlevellock-futex.h: Replace
index 87fda7d8e716e08cd997a8c35f5a5bd02fa91019..0192eecf2570865a166b4fd66e8bdf58c6591650 100644 (file)
@@ -669,6 +669,16 @@ The system does not have sufficient memory.
 @end table
 @end deftypefun
 
+@comment semaphore.h
+@comment POSIX-proposed
+@deftypefun int sem_clockwait (sem_t *@var{sem}, clockid_t @var{clockid},
+                               const struct timespec *@var{abstime})
+Behaves like @code{sem_timedwait} except the time @var{abstime} is measured
+against the clock specified by @var{clockid} rather than
+@code{CLOCK_REALTIME}.  Currently, @var{clockid} must be either
+@code{CLOCK_MONOTONIC} or @code{CLOCK_REALTIME}.
+@end deftypefun
+
 @c FIXME these are undocumented:
 @c pthread_atfork
 @c pthread_attr_destroy
index d23a23558134279e72f7f9ccb7b02ee3d63dc2ad..fefdeb3be473a29ddc072b8efa42e4b818025fed 100644 (file)
@@ -113,7 +113,7 @@ libpthread-routines = nptl-init nptlfreeres vars events version pt-interp \
                      sem_init sem_destroy \
                      sem_open sem_close sem_unlink \
                      sem_getvalue \
-                     sem_wait sem_timedwait sem_post \
+                     sem_wait sem_timedwait sem_clockwait sem_post \
                      cleanup cleanup_defer cleanup_compat \
                      cleanup_defer_compat unwind \
                      pt-longjmp pt-cleanup\
@@ -194,6 +194,7 @@ CFLAGS-pthread_once.c += $(uses-callbacks) -fexceptions \
 CFLAGS-pthread_cond_wait.c += -fexceptions -fasynchronous-unwind-tables
 CFLAGS-sem_wait.c += -fexceptions -fasynchronous-unwind-tables
 CFLAGS-sem_timedwait.c += -fexceptions -fasynchronous-unwind-tables
+CFLAGS-sem_clockwait.c = -fexceptions -fasynchronous-unwind-tables
 
 # These are the function wrappers we have to duplicate here.
 CFLAGS-fcntl.c += -fexceptions -fasynchronous-unwind-tables
@@ -263,7 +264,7 @@ tests = tst-attr1 tst-attr2 tst-attr3 tst-default-attr \
        tst-key1 tst-key2 tst-key3 tst-key4 \
        tst-sem1 tst-sem2 tst-sem3 tst-sem4 tst-sem5 tst-sem6 tst-sem7 \
        tst-sem8 tst-sem9 tst-sem10 tst-sem14 \
-       tst-sem15 tst-sem16 \
+       tst-sem15 tst-sem16 tst-sem17 \
        tst-barrier1 tst-barrier2 tst-barrier3 tst-barrier4 \
        tst-align tst-align3 \
        tst-basic1 tst-basic2 tst-basic3 tst-basic4 tst-basic5 tst-basic6 \
index 6007fd03e7ed117ce331f7edea6e498dde7cef47..4f0e837507094e51419f944ba6fc72a1919e1a83 100644 (file)
@@ -276,6 +276,10 @@ libpthread {
     cnd_timedwait; cnd_wait; tss_create; tss_delete; tss_get; tss_set;
   }
 
+  GLIBC_2.30 {
+    sem_clockwait;
+  }
+
   GLIBC_PRIVATE {
     __pthread_initialize_minimal;
     __pthread_clock_gettime; __pthread_clock_settime;
diff --git a/nptl/sem_clockwait.c b/nptl/sem_clockwait.c
new file mode 100644 (file)
index 0000000..23a6c08
--- /dev/null
@@ -0,0 +1,45 @@
+/* sem_clockwait -- wait on a semaphore with timeout using the specified
+   clock.
+
+   Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include "sem_waitcommon.c"
+
+int
+sem_clockwait (sem_t *sem, clockid_t clockid,
+              const struct timespec *abstime)
+{
+  /* Check that supplied clockid is one we support, even if we don't end up
+     waiting.  */
+  if (!futex_abstimed_supported_clockid (clockid))
+    {
+      __set_errno (EINVAL);
+      return -1;
+    }
+
+  if (abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000)
+    {
+      __set_errno (EINVAL);
+      return -1;
+    }
+
+  if (__new_sem_wait_fast ((struct new_sem *) sem, 0) == 0)
+    return 0;
+  else
+    return __new_sem_wait_slow ((struct new_sem *) sem, clockid, abstime);
+}
index 3dd71ab2fa8c7ff34c87db1048a6296acc79ad4b..0918d8bd107fddf0750be89eb83059470602c9f1 100644 (file)
@@ -36,5 +36,6 @@ sem_timedwait (sem_t *sem, const struct timespec *abstime)
   if (__new_sem_wait_fast ((struct new_sem *) sem, 0) == 0)
     return 0;
   else
-    return __new_sem_wait_slow((struct new_sem *) sem, abstime);
+    return __new_sem_wait_slow ((struct new_sem *) sem,
+                               CLOCK_REALTIME, abstime);
 }
index 6a2d26bd1a1c0b301343d3afecd2e0cbf0e605db..20a8b9d3776fd6d157ecac354fb24221bbfb2722 100644 (file)
@@ -39,7 +39,8 @@ __new_sem_wait (sem_t *sem)
   if (__new_sem_wait_fast ((struct new_sem *) sem, 0) == 0)
     return 0;
   else
-    return __new_sem_wait_slow((struct new_sem *) sem, NULL);
+    return __new_sem_wait_slow ((struct new_sem *) sem,
+                               CLOCK_REALTIME, NULL);
 }
 versioned_symbol (libpthread, __new_sem_wait, sem_wait, GLIBC_2_1);
 
index 425d040dd41193c03845dc0e95b4a0e5d32bd3a3..cad56e996da68cb79a1ed9c55ebeef842d05afbb 100644 (file)
@@ -103,19 +103,19 @@ __sem_wait_cleanup (void *arg)
    users don't seem to need it.  */
 static int
 __attribute__ ((noinline))
-do_futex_wait (struct new_sem *sem, const struct timespec *abstime)
+do_futex_wait (struct new_sem *sem, clockid_t clockid,
+              const struct timespec *abstime)
 {
   int err;
 
 #if __HAVE_64B_ATOMICS
   err = futex_abstimed_wait_cancelable (
       (unsigned int *) &sem->data + SEM_VALUE_OFFSET, 0,
-      CLOCK_REALTIME, abstime,
+      clockid, abstime,
       sem->private);
 #else
   err = futex_abstimed_wait_cancelable (&sem->value, SEM_NWAITERS_MASK,
-                                       CLOCK_REALTIME, abstime,
-                                       sem->private);
+                                       clockid, abstime, sem->private);
 #endif
 
   return err;
@@ -162,7 +162,8 @@ __new_sem_wait_fast (struct new_sem *sem, int definitive_result)
 /* Slow path that blocks.  */
 static int
 __attribute__ ((noinline))
-__new_sem_wait_slow (struct new_sem *sem, const struct timespec *abstime)
+__new_sem_wait_slow (struct new_sem *sem, clockid_t clockid,
+                    const struct timespec *abstime)
 {
   int err = 0;
 
@@ -180,7 +181,7 @@ __new_sem_wait_slow (struct new_sem *sem, const struct timespec *abstime)
       /* If there is no token available, sleep until there is.  */
       if ((d & SEM_VALUE_MASK) == 0)
        {
-         err = do_futex_wait (sem, abstime);
+         err = do_futex_wait (sem, clockid, abstime);
          /* A futex return value of 0 or EAGAIN is due to a real or spurious
             wake-up, or due to a change in the number of tokens.  We retry in
             these cases.
@@ -281,7 +282,7 @@ __new_sem_wait_slow (struct new_sem *sem, const struct timespec *abstime)
          if ((v >> SEM_VALUE_SHIFT) == 0)
            {
              /* See __HAVE_64B_ATOMICS variant.  */
-             err = do_futex_wait(sem, abstime);
+             err = do_futex_wait (sem, clockid, abstime);
              if (err == ETIMEDOUT || err == EINTR)
                {
                  __set_errno (err);
index 28d37ed0cb58bec5da180989bec4ebeb271224bc..d7baa2ae582d563b172b3d4e1eca5ff1ba388fb8 100644 (file)
@@ -6,9 +6,14 @@
 #include <internaltypes.h>
 #include <support/check.h>
 
+/* A bogus clock value that tells run_test to use sem_timedwait rather than
+   sem_clockwait.  */
+#define CLOCK_USE_TIMEDWAIT (-1)
 
-static int
-do_test (void)
+typedef int (*waitfn_t)(sem_t *, struct timespec *);
+
+static void
+do_test_wait (waitfn_t waitfn, const char *fnname)
 {
   union
   {
@@ -16,11 +21,13 @@ do_test (void)
     struct new_sem ns;
   } u;
 
+  printf ("do_test_wait: %s\n", fnname);
+
   TEST_COMPARE (sem_init (&u.s, 0, 0), 0);
 
   struct timespec ts = { 0, 1000000001 };      /* Invalid.  */
   errno = 0;
-  TEST_VERIFY_EXIT (sem_timedwait (&u.s, &ts) < 0);
+  TEST_VERIFY_EXIT (waitfn (&u.s, &ts) < 0);
   TEST_COMPARE (errno, EINVAL);
 
 #if __HAVE_64B_ATOMICS
@@ -33,7 +40,7 @@ do_test (void)
   ts.tv_sec = /* Invalid.  */ -2;
   ts.tv_nsec = 0;
   errno = 0;
-  TEST_VERIFY_EXIT (sem_timedwait (&u.s, &ts) < 0);
+  TEST_VERIFY_EXIT (waitfn (&u.s, &ts) < 0);
   TEST_COMPARE (errno, ETIMEDOUT);
 #if __HAVE_64B_ATOMICS
   nwaiters = (u.ns.data >> SEM_NWAITERS_SHIFT);
@@ -41,7 +48,31 @@ do_test (void)
   nwaiters = u.ns.nwaiters;
 #endif
   TEST_COMPARE (nwaiters, 0);
+}
 
+int test_sem_timedwait (sem_t *sem, struct timespec *ts)
+{
+  return sem_timedwait (sem, ts);
+}
+
+int test_sem_clockwait_monotonic (sem_t *sem, struct timespec *ts)
+{
+  return sem_clockwait (sem, CLOCK_MONOTONIC, ts);
+}
+
+int test_sem_clockwait_realtime (sem_t *sem, struct timespec *ts)
+{
+  return sem_clockwait (sem, CLOCK_REALTIME, ts);
+}
+
+static int do_test (void)
+{
+  do_test_wait (&test_sem_timedwait,
+                "sem_timedwait");
+  do_test_wait (&test_sem_clockwait_monotonic,
+                "sem_clockwait(monotonic)");
+  do_test_wait (&test_sem_clockwait_realtime,
+                "sem_clockwait(realtime)");
   return 0;
 }
 
diff --git a/nptl/tst-sem17.c b/nptl/tst-sem17.c
new file mode 100644 (file)
index 0000000..69e2387
--- /dev/null
@@ -0,0 +1,76 @@
+/* Test unsupported/bad clocks passed to sem_clockwait.
+
+   Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <semaphore.h>
+#include <stdio.h>
+#include <time.h>
+#include <unistd.h>
+#include <sys/time.h>
+#include <support/check.h>
+#include <support/timespec.h>
+
+
+#define NOT_A_VALID_CLOCK 123456
+
+static int
+do_test (void)
+{
+  sem_t s;
+  TEST_COMPARE (sem_init (&s, 0, 1), 0);
+
+  const struct timespec ts = make_timespec (0, 0);
+
+  /* These clocks are meaningless to sem_clockwait.  */
+#if defined(CLOCK_PROCESS_CPUTIME_ID)
+  TEST_COMPARE (sem_clockwait (&s, CLOCK_PROCESS_CPUTIME_ID, &ts), -1);
+  TEST_COMPARE (errno, EINVAL);
+#endif
+#if defined(CLOCK_THREAD_CPUTIME_ID)
+  TEST_COMPARE (sem_clockwait (&s, CLOCK_THREAD_CPUTIME_ID, &ts), -1);
+  TEST_COMPARE (errno, EINVAL);
+#endif
+
+  /* These clocks might be meaningful, but are currently unsupported
+     by pthread_cond_clockwait.  */
+#if defined(CLOCK_REALTIME_COARSE)
+  TEST_COMPARE (sem_clockwait (&s, CLOCK_REALTIME_COARSE, &ts), -1);
+  TEST_COMPARE (errno, EINVAL);
+#endif
+#if defined(CLOCK_MONOTONIC_RAW)
+  TEST_COMPARE (sem_clockwait (&s, CLOCK_MONOTONIC_RAW, &ts), -1);
+  TEST_COMPARE (errno, EINVAL);
+#endif
+#if defined(CLOCK_MONOTONIC_COARSE)
+  TEST_COMPARE (sem_clockwait (&s, CLOCK_MONOTONIC_COARSE, &ts), -1);
+  TEST_COMPARE (errno, EINVAL);
+#endif
+#if defined(CLOCK_BOOTTIME)
+  TEST_COMPARE (sem_clockwait (&s, CLOCK_BOOTTIME, &ts), -1);
+  TEST_COMPARE (errno, EINVAL);
+#endif
+
+  /* This is a completely invalid clock.  */
+  TEST_COMPARE (sem_clockwait (&s, NOT_A_VALID_CLOCK, &ts), -1);
+  TEST_COMPARE (errno, EINVAL);
+
+  return 0;
+}
+
+#include <support/test-driver.c>
index 396222b85f647feea1035c23bb9e48d4a9c1d972..63b13552b0da9db5ffbb1b6e610d12bea7ed71f8 100644 (file)
 #include <support/timespec.h>
 #include <support/xtime.h>
 
+/* A bogus clock value that tells run_test to use sem_timedwait rather than
+   sem_clockwait.  */
+#define CLOCK_USE_TIMEDWAIT (-1)
 
-static int
-do_test (void)
+static void
+do_test_clock (clockid_t clockid)
 {
+  const clockid_t clockid_for_get =
+    clockid == CLOCK_USE_TIMEDWAIT ? CLOCK_REALTIME : clockid;
   sem_t s;
   struct timespec ts;
 
@@ -36,14 +41,22 @@ do_test (void)
   TEST_COMPARE (TEMP_FAILURE_RETRY (sem_wait (&s)), 0);
 
   /* We wait for half a second.  */
-  xclock_gettime (CLOCK_REALTIME, &ts);
+  xclock_gettime (clockid_for_get, &ts);
   ts = timespec_add (ts, make_timespec (0, TIMESPEC_HZ/2));
 
   errno = 0;
-  TEST_COMPARE (TEMP_FAILURE_RETRY (sem_timedwait (&s, &ts)), -1);
+  TEST_COMPARE (TEMP_FAILURE_RETRY ((clockid == CLOCK_USE_TIMEDWAIT)
+                                    ? sem_timedwait (&s, &ts)
+                                    : sem_clockwait (&s, clockid, &ts)), -1);
   TEST_COMPARE (errno, ETIMEDOUT);
-  TEST_TIMESPEC_NOW_OR_AFTER (CLOCK_REALTIME, ts);
+  TEST_TIMESPEC_NOW_OR_AFTER (clockid_for_get, ts);
+}
 
+static int do_test (void)
+{
+  do_test_clock (CLOCK_USE_TIMEDWAIT);
+  do_test_clock (CLOCK_REALTIME);
+  do_test_clock (CLOCK_MONOTONIC);
   return 0;
 }
 
index 87c054392c58748c6cf72bb8eee011db44330cae..6e74aa31760e238f39d4099384d5062961efa826 100644 (file)
@@ -64,6 +64,13 @@ extern int sem_timedwait (sem_t *__restrict __sem,
   __nonnull ((1, 2));
 #endif
 
+#ifdef __USE_GNU
+extern int sem_clockwait (sem_t *__restrict __sem,
+                         clockid_t clock,
+                         const struct timespec *__restrict __abstime)
+  __nonnull ((1, 3));
+#endif
+
 /* Test whether SEM is posted.  */
 extern int sem_trywait (sem_t *__sem) __THROWNL __nonnull ((1));
 
index 6945b7cbe4c2bde823742b76917a9a5f4a297c46..d999abc20aa1595bebd5dd574420b36463746019 100644 (file)
@@ -241,3 +241,4 @@ GLIBC_2.28 tss_create F
 GLIBC_2.28 tss_delete F
 GLIBC_2.28 tss_get F
 GLIBC_2.28 tss_set F
+GLIBC_2.30 sem_clockwait F
index 2d9b958efa99feb8861a9f36a8a77e45239e4df1..6a7950428707868e84ad1486b1f4a69bc9b4a0af 100644 (file)
@@ -254,6 +254,7 @@ GLIBC_2.3.4 pthread_attr_setaffinity_np F
 GLIBC_2.3.4 pthread_getaffinity_np F
 GLIBC_2.3.4 pthread_setaffinity_np F
 GLIBC_2.3.4 pthread_setschedprio F
+GLIBC_2.30 sem_clockwait F
 GLIBC_2.4 pthread_mutex_consistent_np F
 GLIBC_2.4 pthread_mutex_getprioceiling F
 GLIBC_2.4 pthread_mutex_setprioceiling F
index ee3d0290d01f184ed2766dae0d7c728dfa716607..1b56e6a21ddceb3b7532b6f81e20b7fa6faae98d 100644 (file)
@@ -27,6 +27,7 @@ GLIBC_2.28 tss_create F
 GLIBC_2.28 tss_delete F
 GLIBC_2.28 tss_get F
 GLIBC_2.28 tss_set F
+GLIBC_2.30 sem_clockwait F
 GLIBC_2.4 _IO_flockfile F
 GLIBC_2.4 _IO_ftrylockfile F
 GLIBC_2.4 _IO_funlockfile F
index ea4b79a518eec29d85297ea402c0deec2f8473f9..fdf577ca10aa0fcef111fcd3c22a7d66315438e9 100644 (file)
@@ -233,3 +233,4 @@ GLIBC_2.29 tss_set F
 GLIBC_2.29 wait F
 GLIBC_2.29 waitpid F
 GLIBC_2.29 write F
+GLIBC_2.30 sem_clockwait F
index e9b3be6ac8e8f367c4a8b5c7c6bc6bc55c61fe40..6d8e93249c11df2c6c27c420adfdd0b89ae6f405 100644 (file)
@@ -243,6 +243,7 @@ GLIBC_2.3.4 pthread_attr_setaffinity_np F
 GLIBC_2.3.4 pthread_getaffinity_np F
 GLIBC_2.3.4 pthread_setaffinity_np F
 GLIBC_2.3.4 pthread_setschedprio F
+GLIBC_2.30 sem_clockwait F
 GLIBC_2.4 pthread_mutex_consistent_np F
 GLIBC_2.4 pthread_mutex_getprioceiling F
 GLIBC_2.4 pthread_mutex_setprioceiling F
index 7199aae573649f49e40c783b358449f7b6346c71..25667b739f37a4cc1eab9b6bd8b90c86d3005157 100644 (file)
@@ -252,6 +252,7 @@ GLIBC_2.3.4 pthread_attr_setaffinity_np F
 GLIBC_2.3.4 pthread_getaffinity_np F
 GLIBC_2.3.4 pthread_setaffinity_np F
 GLIBC_2.3.4 pthread_setschedprio F
+GLIBC_2.30 sem_clockwait F
 GLIBC_2.4 pthread_mutex_consistent_np F
 GLIBC_2.4 pthread_mutex_getprioceiling F
 GLIBC_2.4 pthread_mutex_setprioceiling F
index e8a65642caec7ff18b44c38ad1f4fea815bd4403..e4e4f85caea24b0039ce949cf0d8b911cc6c2511 100644 (file)
@@ -245,6 +245,7 @@ GLIBC_2.3.4 pthread_attr_setaffinity_np F
 GLIBC_2.3.4 pthread_getaffinity_np F
 GLIBC_2.3.4 pthread_setaffinity_np F
 GLIBC_2.3.4 pthread_setschedprio F
+GLIBC_2.30 sem_clockwait F
 GLIBC_2.4 pthread_mutex_consistent_np F
 GLIBC_2.4 pthread_mutex_getprioceiling F
 GLIBC_2.4 pthread_mutex_setprioceiling F
index ee3d0290d01f184ed2766dae0d7c728dfa716607..1b56e6a21ddceb3b7532b6f81e20b7fa6faae98d 100644 (file)
@@ -27,6 +27,7 @@ GLIBC_2.28 tss_create F
 GLIBC_2.28 tss_delete F
 GLIBC_2.28 tss_get F
 GLIBC_2.28 tss_set F
+GLIBC_2.30 sem_clockwait F
 GLIBC_2.4 _IO_flockfile F
 GLIBC_2.4 _IO_ftrylockfile F
 GLIBC_2.4 _IO_funlockfile F
index 7199aae573649f49e40c783b358449f7b6346c71..25667b739f37a4cc1eab9b6bd8b90c86d3005157 100644 (file)
@@ -252,6 +252,7 @@ GLIBC_2.3.4 pthread_attr_setaffinity_np F
 GLIBC_2.3.4 pthread_getaffinity_np F
 GLIBC_2.3.4 pthread_setaffinity_np F
 GLIBC_2.3.4 pthread_setschedprio F
+GLIBC_2.30 sem_clockwait F
 GLIBC_2.4 pthread_mutex_consistent_np F
 GLIBC_2.4 pthread_mutex_getprioceiling F
 GLIBC_2.4 pthread_mutex_setprioceiling F
index e0fbe6848f7945bd87e45d8bd5e37fce1a3259a1..4b907bb72494c75c2a1c7e7f015eb8c67765d66e 100644 (file)
@@ -241,3 +241,4 @@ GLIBC_2.28 tss_create F
 GLIBC_2.28 tss_delete F
 GLIBC_2.28 tss_get F
 GLIBC_2.28 tss_set F
+GLIBC_2.30 sem_clockwait F
index f60b22efb5b5f683f0ab3ce8be0bc066826effb3..781053da95554a55db3e3c3ee0ca5602045ba41e 100644 (file)
@@ -253,6 +253,7 @@ GLIBC_2.3.4 pthread_attr_setaffinity_np F
 GLIBC_2.3.4 pthread_getaffinity_np F
 GLIBC_2.3.4 pthread_setaffinity_np F
 GLIBC_2.3.4 pthread_setschedprio F
+GLIBC_2.30 sem_clockwait F
 GLIBC_2.4 pthread_mutex_consistent_np F
 GLIBC_2.4 pthread_mutex_getprioceiling F
 GLIBC_2.4 pthread_mutex_setprioceiling F
index f60b22efb5b5f683f0ab3ce8be0bc066826effb3..781053da95554a55db3e3c3ee0ca5602045ba41e 100644 (file)
@@ -253,6 +253,7 @@ GLIBC_2.3.4 pthread_attr_setaffinity_np F
 GLIBC_2.3.4 pthread_getaffinity_np F
 GLIBC_2.3.4 pthread_setaffinity_np F
 GLIBC_2.3.4 pthread_setschedprio F
+GLIBC_2.30 sem_clockwait F
 GLIBC_2.4 pthread_mutex_consistent_np F
 GLIBC_2.4 pthread_mutex_getprioceiling F
 GLIBC_2.4 pthread_mutex_setprioceiling F
index 78cac2ae27b675e2cee4c1656ecde1dc00ac6193..8eca3c2b541138e8ba980f374239d34a864050c4 100644 (file)
@@ -241,3 +241,4 @@ GLIBC_2.28 tss_create F
 GLIBC_2.28 tss_delete F
 GLIBC_2.28 tss_get F
 GLIBC_2.28 tss_set F
+GLIBC_2.30 sem_clockwait F
index c7d9b7898640730da69fe0292ee29d31ef971502..eebe139dde73bacee34ed0e385b92b06419e2f32 100644 (file)
@@ -254,6 +254,7 @@ GLIBC_2.3.4 pthread_getaffinity_np F
 GLIBC_2.3.4 pthread_setaffinity_np F
 GLIBC_2.3.4 pthread_setschedprio F
 GLIBC_2.3.4 siglongjmp F
+GLIBC_2.30 sem_clockwait F
 GLIBC_2.4 pthread_mutex_consistent_np F
 GLIBC_2.4 pthread_mutex_getprioceiling F
 GLIBC_2.4 pthread_mutex_setprioceiling F
index 3500cce6c1124996bbb72d4365b863cd4e8d2346..1d7ef722e7fff2dbffa6f0e64adfb6cb86dac006 100644 (file)
@@ -244,6 +244,7 @@ GLIBC_2.3.4 pthread_getaffinity_np F
 GLIBC_2.3.4 pthread_setaffinity_np F
 GLIBC_2.3.4 pthread_setschedprio F
 GLIBC_2.3.4 siglongjmp F
+GLIBC_2.30 sem_clockwait F
 GLIBC_2.4 pthread_mutex_consistent_np F
 GLIBC_2.4 pthread_mutex_getprioceiling F
 GLIBC_2.4 pthread_mutex_setprioceiling F
index 6945b7cbe4c2bde823742b76917a9a5f4a297c46..d999abc20aa1595bebd5dd574420b36463746019 100644 (file)
@@ -241,3 +241,4 @@ GLIBC_2.28 tss_create F
 GLIBC_2.28 tss_delete F
 GLIBC_2.28 tss_get F
 GLIBC_2.28 tss_set F
+GLIBC_2.30 sem_clockwait F
index c370fda73db917124432a6cdb767fb83ac11f096..c6bddf967c8d3ccd99db8ab9aacbf80ca0a8f7b3 100644 (file)
@@ -235,3 +235,4 @@ GLIBC_2.28 tss_create F
 GLIBC_2.28 tss_delete F
 GLIBC_2.28 tss_get F
 GLIBC_2.28 tss_set F
+GLIBC_2.30 sem_clockwait F
index f093634d7edce2f23d658ead571d5773b33753af..229a3bc4b96217fc57a907c1f7a2343a46575d9f 100644 (file)
@@ -254,6 +254,7 @@ GLIBC_2.3.4 pthread_attr_setaffinity_np F
 GLIBC_2.3.4 pthread_getaffinity_np F
 GLIBC_2.3.4 pthread_setaffinity_np F
 GLIBC_2.3.4 pthread_setschedprio F
+GLIBC_2.30 sem_clockwait F
 GLIBC_2.4 pthread_mutex_consistent_np F
 GLIBC_2.4 pthread_mutex_getprioceiling F
 GLIBC_2.4 pthread_mutex_setprioceiling F
index 47204f166c29a773f13024d848fb1b96f4a81b33..0ef4a177625e12132875db783d3c4380b5ea720c 100644 (file)
@@ -245,6 +245,7 @@ GLIBC_2.3.4 pthread_attr_setaffinity_np F
 GLIBC_2.3.4 pthread_getaffinity_np F
 GLIBC_2.3.4 pthread_setaffinity_np F
 GLIBC_2.3.4 pthread_setschedprio F
+GLIBC_2.30 sem_clockwait F
 GLIBC_2.4 pthread_mutex_consistent_np F
 GLIBC_2.4 pthread_mutex_getprioceiling F
 GLIBC_2.4 pthread_mutex_setprioceiling F
index e9b3be6ac8e8f367c4a8b5c7c6bc6bc55c61fe40..6d8e93249c11df2c6c27c420adfdd0b89ae6f405 100644 (file)
@@ -243,6 +243,7 @@ GLIBC_2.3.4 pthread_attr_setaffinity_np F
 GLIBC_2.3.4 pthread_getaffinity_np F
 GLIBC_2.3.4 pthread_setaffinity_np F
 GLIBC_2.3.4 pthread_setschedprio F
+GLIBC_2.30 sem_clockwait F
 GLIBC_2.4 pthread_mutex_consistent_np F
 GLIBC_2.4 pthread_mutex_getprioceiling F
 GLIBC_2.4 pthread_mutex_setprioceiling F
index 2d9b958efa99feb8861a9f36a8a77e45239e4df1..6a7950428707868e84ad1486b1f4a69bc9b4a0af 100644 (file)
@@ -254,6 +254,7 @@ GLIBC_2.3.4 pthread_attr_setaffinity_np F
 GLIBC_2.3.4 pthread_getaffinity_np F
 GLIBC_2.3.4 pthread_setaffinity_np F
 GLIBC_2.3.4 pthread_setschedprio F
+GLIBC_2.30 sem_clockwait F
 GLIBC_2.4 pthread_mutex_consistent_np F
 GLIBC_2.4 pthread_mutex_getprioceiling F
 GLIBC_2.4 pthread_mutex_setprioceiling F
index e8a65642caec7ff18b44c38ad1f4fea815bd4403..e4e4f85caea24b0039ce949cf0d8b911cc6c2511 100644 (file)
@@ -245,6 +245,7 @@ GLIBC_2.3.4 pthread_attr_setaffinity_np F
 GLIBC_2.3.4 pthread_getaffinity_np F
 GLIBC_2.3.4 pthread_setaffinity_np F
 GLIBC_2.3.4 pthread_setschedprio F
+GLIBC_2.30 sem_clockwait F
 GLIBC_2.4 pthread_mutex_consistent_np F
 GLIBC_2.4 pthread_mutex_getprioceiling F
 GLIBC_2.4 pthread_mutex_setprioceiling F
index 4fbb72ffb37ba68933b0bfccfa7447c9385f1895..391809045c234435411c7a12aebf288559633bb3 100644 (file)
@@ -243,6 +243,7 @@ GLIBC_2.3.4 pthread_attr_setaffinity_np F
 GLIBC_2.3.4 pthread_getaffinity_np F
 GLIBC_2.3.4 pthread_setaffinity_np F
 GLIBC_2.3.4 pthread_setschedprio F
+GLIBC_2.30 sem_clockwait F
 GLIBC_2.4 pthread_mutex_consistent_np F
 GLIBC_2.4 pthread_mutex_getprioceiling F
 GLIBC_2.4 pthread_mutex_setprioceiling F
index eec4b99b8bb69d7418b0b983f39240c1a76af93f..b8fd91f62ce54c9da7716cab9d13ee04619e3303 100644 (file)
@@ -241,3 +241,4 @@ GLIBC_2.28 tss_create F
 GLIBC_2.28 tss_delete F
 GLIBC_2.28 tss_get F
 GLIBC_2.28 tss_set F
+GLIBC_2.30 sem_clockwait F