]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
nptl: Add POSIX-proposed pthread_mutex_clocklock
authorMike Crowe <mac@mcrowe.com>
Mon, 24 Jun 2019 19:48:14 +0000 (19:48 +0000)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Fri, 12 Jul 2019 13:36:25 +0000 (13:36 +0000)
Add POSIX-proposed pthread_mutex_clocklock function that works like
pthread_mutex_timedlock but takes a clockid parameter to measure the
abstime parameter against.

* sysdeps/nptl/pthread.h: Add pthread_mutex_clocklock.
* nptl/DESIGN-systemtap-probes.txt: Likewise.
* nptl/pthread_mutex_timedlock.c
(__pthread_mutex_clocklock_common): Rename from
__pthread_mutex_timedlock and add clockid parameter. Pass this
parameter to lll_clocklock and lll_clocklock_elision in place of
CLOCK_REALTIME. (__pthread_mutex_clocklock): New function to add
LIBC_PROBE and validate clockid parameter before calling
__pthread_mutex_clocklock_common. (__pthread_mutex_timedlock): New
implementation to add LIBC_PROBE and calls
__pthread_mutex_clocklock_common passing CLOCK_REALTIME as the
clockid.
* nptl/Makefile: Add tst-mutex11.c.
* nptl/tst-abstime.c (th): Add tests for pthread_mutex_clocklock.
* nptl/tst-mutex11.c: New tests for passing invalid and unsupported
clockid parameters to pthread_mutex_clocklock.
* nptl/tst-mutex5.c (do_test_clock): Rename from do_test and take
clockid parameter to indicate which clock to be used. Call
pthread_mutex_timedlock or pthread_mutex_clocklock as appropriate.
(do_test): Call do_test_clock to separately test
pthread_mutex_timedlock, pthread_mutex_clocklock(CLOCK_REALTIME)
and pthread_mutex_clocklock(CLOCK_MONOTONIC).
* nptl/tst-mutex9.c: Likewise.
* nptl/Versions (GLIBC_2.30): Add pthread_mutex_clocklock.
* 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.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
35 files changed:
ChangeLog
nptl/DESIGN-systemtap-probes.txt
nptl/Makefile
nptl/Versions
nptl/pthread_cond_wait.c
nptl/pthread_mutex_timedlock.c
nptl/tst-abstime.c
nptl/tst-mutex11.c [new file with mode: 0644]
nptl/tst-mutex5.c
nptl/tst-mutex9.c
sysdeps/nptl/pthread.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 a09519c80774a30c3b9b4019e19863153df69486..7f7555984bde162953e7e86e736bd5c21786c0ce 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,81 @@
 2019-07-12  Mike Crowe  <mac@mcrowe.com>
 
+       nptl: Add POSIX-proposed pthread_mutex_clocklock function that
+       works like pthread_mutex_timedlock but takes a clockid parameter to
+       measure the abstime parameter against.
+       * sysdeps/nptl/pthread.h: Add pthread_mutex_clocklock.
+       * nptl/DESIGN-systemtap-probes.txt: Likewise.
+       * nptl/pthread_mutex_timedlock.c
+       (__pthread_mutex_clocklock_common): Rename from
+       __pthread_mutex_timedlock and add clockid parameter. Pass this
+       parameter to lll_clocklock and lll_clocklock_elision in place of
+       CLOCK_REALTIME. (__pthread_mutex_clocklock): New function to add
+       LIBC_PROBE and validate clockid parameter before calling
+       __pthread_mutex_clocklock_common. (__pthread_mutex_timedlock): New
+       implementation to add LIBC_PROBE and calls
+       __pthread_mutex_clocklock_common passing CLOCK_REALTIME as the
+       clockid.
+       * nptl/Makefile: Add tst-mutex11.c.
+       * nptl/tst-abstime.c (th): Add tests for pthread_mutex_clocklock.
+       * nptl/tst-mutex11.c: New tests for passing invalid and unsupported
+       clockid parameters to pthread_mutex_clocklock.
+       * nptl/tst-mutex5.c (do_test_clock): Rename from do_test and take
+       clockid parameter to indicate which clock to be used. Call
+       pthread_mutex_timedlock or pthread_mutex_clocklock as appropriate.
+       (do_test): Call do_test_clock to separately test
+       pthread_mutex_timedlock, pthread_mutex_clocklock(CLOCK_REALTIME)
+       and pthread_mutex_clocklock(CLOCK_MONOTONIC).
+       * nptl/tst-mutex9.c: Likewise.
+       * nptl/Versions (GLIBC_2.30): Add pthread_mutex_clocklock.
+       * 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: Rename lll_timedlock to lll_clocklock and add clockid
        parameter to indicate the clock that the abstime parameter should
        be measured against in preparation for adding
index ac972a954261fb1f4f991d57a243f836eddedf61..6a62e25532765f5f6a6e8c8dcc618301a8f82d07 100644 (file)
@@ -32,6 +32,9 @@ mutex_entry   - probe for entry to the pthread_mutex_lock function
               arg1 = address of mutex lock
 mutex_timedlock_entry - probe for entry to the pthread_mutex_timedlock function
                       arg1 = address of mutex lock, arg2 = address of timespec
+mutex_clocklock_entry - probe for entry to the pthread_mutex_clocklock function
+                      arg1 = address of mutex lock, arg2 = clockid,
+                     arg3 = address of timespec
 mutex_release - probe for pthread_mutex_unlock after the successful release of a
                 mutex lock
               arg1 = address of mutex lock
index 106a9812971fab903314ffc6703e385dbb9eadb9..0567e77a790b9f9bbba8c88e9137941df7541298 100644 (file)
@@ -244,7 +244,7 @@ LDLIBS-tst-minstack-throw = -lstdc++
 
 tests = tst-attr1 tst-attr2 tst-attr3 tst-default-attr \
        tst-mutex1 tst-mutex2 tst-mutex3 tst-mutex4 tst-mutex5 tst-mutex6 \
-       tst-mutex7 tst-mutex9 tst-mutex10 tst-mutex5a tst-mutex7a \
+       tst-mutex7 tst-mutex9 tst-mutex10 tst-mutex11 tst-mutex5a tst-mutex7a \
        tst-mutex7robust tst-mutexpi1 tst-mutexpi2 tst-mutexpi3 tst-mutexpi4 \
        tst-mutexpi5 tst-mutexpi5a tst-mutexpi6 tst-mutexpi7 tst-mutexpi7a \
        tst-mutexpi9 \
index f504877f2ab8f155fa7f2453379f724e45ecf4a8..f2ea2b32a1b8fa193563b9ff36a922ff4fcb094f 100644 (file)
@@ -279,6 +279,7 @@ libpthread {
   GLIBC_2.30 {
     sem_clockwait; pthread_cond_clockwait;
     pthread_rwlock_clockrdlock; pthread_rwlock_clockwrlock;
+    pthread_mutex_clocklock;
   }
 
   GLIBC_PRIVATE {
index 558f930cd205dfe79c568f164a3cd70cfa5f3bc9..68ec754003ef2066167955915f1c1fb9622659ed 100644 (file)
@@ -655,6 +655,10 @@ __pthread_cond_timedwait (pthread_cond_t *cond, pthread_mutex_t *mutex,
                     ? CLOCK_MONOTONIC : CLOCK_REALTIME;
   return __pthread_cond_wait_common (cond, mutex, clockid, abstime);
 }
+versioned_symbol (libpthread, __pthread_cond_wait, pthread_cond_wait,
+                 GLIBC_2_3_2);
+versioned_symbol (libpthread, __pthread_cond_timedwait, pthread_cond_timedwait,
+                 GLIBC_2_3_2);
 
 /* See __pthread_cond_wait_common.  */
 int
@@ -677,9 +681,4 @@ __pthread_cond_clockwait (pthread_cond_t *cond, pthread_mutex_t *mutex,
 
   return __pthread_cond_wait_common (cond, mutex, clockid, abstime);
 }
-
-versioned_symbol (libpthread, __pthread_cond_wait, pthread_cond_wait,
-                 GLIBC_2_3_2);
-versioned_symbol (libpthread, __pthread_cond_timedwait, pthread_cond_timedwait,
-                 GLIBC_2_3_2);
 weak_alias (__pthread_cond_clockwait, pthread_cond_clockwait);
index 10a9989a671c4f42aaa678f6cf274f7b5cd05227..52c258e33d960b390a6c4c0cb4106d0b15de2a4b 100644 (file)
 #endif
 
 int
-__pthread_mutex_timedlock (pthread_mutex_t *mutex,
-                          const struct timespec *abstime)
+__pthread_mutex_clocklock_common (pthread_mutex_t *mutex,
+                                 clockid_t clockid,
+                                 const struct timespec *abstime)
 {
   int oldval;
   pid_t id = THREAD_GETMEM (THREAD_SELF, tid);
   int result = 0;
 
-  LIBC_PROBE (mutex_timedlock_entry, 2, mutex, abstime);
-
   /* We must not check ABSTIME here.  If the thread does not block
      abstime must not be checked for a valid value.  */
 
@@ -76,7 +75,7 @@ __pthread_mutex_timedlock (pthread_mutex_t *mutex,
        }
 
       /* We have to get the mutex.  */
-      result = lll_clocklock (mutex->__data.__lock, CLOCK_REALTIME, abstime,
+      result = lll_clocklock (mutex->__data.__lock, clockid, abstime,
                              PTHREAD_MUTEX_PSHARED (mutex));
 
       if (result != 0)
@@ -99,7 +98,7 @@ __pthread_mutex_timedlock (pthread_mutex_t *mutex,
       FORCE_ELISION (mutex, goto elision);
     simple:
       /* Normal mutex.  */
-      result = lll_clocklock (mutex->__data.__lock, CLOCK_REALTIME, abstime,
+      result = lll_clocklock (mutex->__data.__lock, clockid, abstime,
                              PTHREAD_MUTEX_PSHARED (mutex));
       break;
 
@@ -108,7 +107,7 @@ __pthread_mutex_timedlock (pthread_mutex_t *mutex,
       /* Don't record ownership */
       return lll_clocklock_elision (mutex->__data.__lock,
                                    mutex->__data.__spins,
-                                   CLOCK_REALTIME, abstime,
+                                   clockid, abstime,
                                    PTHREAD_MUTEX_PSHARED (mutex));
 
 
@@ -126,7 +125,7 @@ __pthread_mutex_timedlock (pthread_mutex_t *mutex,
              if (cnt++ >= max_cnt)
                {
                  result = lll_clocklock (mutex->__data.__lock,
-                                         CLOCK_REALTIME, abstime,
+                                         clockid, abstime,
                                          PTHREAD_MUTEX_PSHARED (mutex));
                  break;
                }
@@ -269,7 +268,7 @@ __pthread_mutex_timedlock (pthread_mutex_t *mutex,
 
          /* Block using the futex.  */
          int err = lll_futex_clock_wait_bitset (&mutex->__data.__lock,
-             oldval, CLOCK_REALTIME, abstime,
+             oldval, clockid, abstime,
              PTHREAD_ROBUST_MUTEX_PSHARED (mutex));
          /* The futex call timed out.  */
          if (err == -ETIMEDOUT)
@@ -405,7 +404,7 @@ __pthread_mutex_timedlock (pthread_mutex_t *mutex,
                    struct timespec reltime;
                    struct timespec now;
 
-                   INTERNAL_SYSCALL (clock_gettime, __err, 2, CLOCK_REALTIME,
+                   INTERNAL_SYSCALL (clock_gettime, __err, 2, clockid,
                                      &now);
                    reltime.tv_sec = abstime->tv_sec - now.tv_sec;
                    reltime.tv_nsec = abstime->tv_nsec - now.tv_nsec;
@@ -623,4 +622,25 @@ __pthread_mutex_timedlock (pthread_mutex_t *mutex,
  out:
   return result;
 }
+
+int
+__pthread_mutex_clocklock (pthread_mutex_t *mutex,
+                          clockid_t clockid,
+                          const struct timespec *abstime)
+{
+  if (__glibc_unlikely (!lll_futex_supported_clockid (clockid)))
+    return EINVAL;
+
+  LIBC_PROBE (mutex_clocklock_entry, 3, mutex, clockid, abstime);
+  return __pthread_mutex_clocklock_common (mutex, clockid, abstime);
+}
+weak_alias (__pthread_mutex_clocklock, pthread_mutex_clocklock)
+
+int
+__pthread_mutex_timedlock (pthread_mutex_t *mutex,
+                          const struct timespec *abstime)
+{
+  LIBC_PROBE (mutex_timedlock_entry, 2, mutex, abstime);
+  return __pthread_mutex_clocklock_common (mutex, CLOCK_REALTIME, abstime);
+}
 weak_alias (__pthread_mutex_timedlock, pthread_mutex_timedlock)
index c5040c591a238c0a718a7f1d30922d979d932b15..30dea4d5b41d13205d9ee352eac26ec9e3ea474e 100644 (file)
@@ -36,6 +36,8 @@ th (void *arg)
   struct timespec t = { -2, 0 };
 
   TEST_COMPARE (pthread_mutex_timedlock (&m1, &t), ETIMEDOUT);
+  TEST_COMPARE (pthread_mutex_clocklock (&m1, CLOCK_REALTIME, &t), ETIMEDOUT);
+  TEST_COMPARE (pthread_mutex_clocklock (&m1, CLOCK_MONOTONIC, &t), ETIMEDOUT);
   TEST_COMPARE (pthread_rwlock_timedrdlock (&rw1, &t), ETIMEDOUT);
   TEST_COMPARE (pthread_rwlock_timedwrlock (&rw2, &t), ETIMEDOUT);
   TEST_COMPARE (pthread_rwlock_clockrdlock (&rw1, CLOCK_REALTIME, &t),
diff --git a/nptl/tst-mutex11.c b/nptl/tst-mutex11.c
new file mode 100644 (file)
index 0000000..dc1055e
--- /dev/null
@@ -0,0 +1,69 @@
+/* Test unsupported/bad clocks passed to pthread_mutex_clocklock.
+
+   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 <pthread.h>
+#include <stdio.h>
+#include <time.h>
+#include <unistd.h>
+#include <support/check.h>
+
+static pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER;
+
+static void test_bad_clockid (clockid_t clockid)
+{
+  const struct timespec ts = {0,0};
+  TEST_COMPARE (pthread_mutex_clocklock (&mut, clockid, &ts), EINVAL);
+}
+
+#define NOT_A_VALID_CLOCK 123456
+
+static int
+do_test (void)
+{
+  /* These clocks are meaningless to pthread_mutex_clocklock.  */
+#if defined(CLOCK_PROCESS_CPUTIME_ID)
+  test_bad_clockid (CLOCK_PROCESS_CPUTIME_ID);
+#endif
+#if defined(CLOCK_THREAD_CPUTIME_ID)
+  test_bad_clockid (CLOCK_PROCESS_CPUTIME_ID);
+#endif
+
+  /* These clocks might be meaningful, but are currently unsupported by
+     pthread_mutex_clocklock.  */
+#if defined(CLOCK_REALTIME_COARSE)
+  test_bad_clockid (CLOCK_REALTIME_COARSE);
+#endif
+#if defined(CLOCK_MONOTONIC_RAW)
+  test_bad_clockid (CLOCK_MONOTONIC_RAW);
+#endif
+#if defined(CLOCK_MONOTONIC_COARSE)
+  test_bad_clockid (CLOCK_MONOTONIC_COARSE);
+#endif
+#if defined(CLOCK_BOOTTIME)
+  test_bad_clockid (CLOCK_BOOTTIME);
+#endif
+
+  /* This is a completely invalid clock.  */
+  test_bad_clockid (NOT_A_VALID_CLOCK);
+
+  return 0;
+}
+
+#include <support/test-driver.c>
index fb27152ecc3a1c714cfcff0288de6850d208f5c4..7e236ade4dcf95b83e621d7713a7b4e332412d76 100644 (file)
 # define TYPE PTHREAD_MUTEX_NORMAL
 #endif
 
+/* A bogus clock value that tells run_test to use
+   pthread_mutex_timedlock rather than pthread_mutex_clocklock.  */
+#define CLOCK_USE_TIMEDLOCK (-1)
 
 static int
-do_test (void)
+do_test_clock (clockid_t clockid, const char *fnname)
 {
   pthread_mutex_t m;
   pthread_mutexattr_t a;
+  const clockid_t clockid_for_get =
+    (clockid == CLOCK_USE_TIMEDLOCK) ? CLOCK_REALTIME : clockid;
 
   TEST_COMPARE (pthread_mutexattr_init (&a), 0);
   TEST_COMPARE (pthread_mutexattr_settype (&a, TYPE), 0);
@@ -62,16 +67,23 @@ do_test (void)
     FAIL_EXIT1 ("mutex_trylock succeeded");
 
   /* Wait 2 seconds.  */
-  struct timespec ts_timeout = timespec_add (xclock_now (CLOCK_REALTIME),
+  struct timespec ts_timeout = timespec_add (xclock_now (clockid_for_get),
                                              make_timespec (2, 0));
 
-  TEST_COMPARE (pthread_mutex_timedlock (&m, &ts_timeout), ETIMEDOUT);
-  TEST_TIMESPEC_BEFORE_NOW (ts_timeout, CLOCK_REALTIME);
+  if (clockid == CLOCK_USE_TIMEDLOCK)
+    TEST_COMPARE (pthread_mutex_timedlock (&m, &ts_timeout), ETIMEDOUT);
+  else
+    TEST_COMPARE (pthread_mutex_clocklock (&m, clockid, &ts_timeout),
+                 ETIMEDOUT);
+  TEST_TIMESPEC_BEFORE_NOW (ts_timeout, clockid_for_get);
 
   /* The following makes the ts value invalid.  */
   ts_timeout.tv_nsec += 1000000000;
 
-  TEST_COMPARE (pthread_mutex_timedlock (&m, &ts_timeout), EINVAL);
+  if (clockid == CLOCK_USE_TIMEDLOCK)
+    TEST_COMPARE (pthread_mutex_timedlock (&m, &ts_timeout), EINVAL);
+  else
+    TEST_COMPARE (pthread_mutex_clocklock (&m, clockid, &ts_timeout), EINVAL);
   TEST_COMPARE (pthread_mutex_unlock (&m), 0);
 
   const struct timespec ts_start = xclock_now (CLOCK_REALTIME);
@@ -79,9 +91,12 @@ do_test (void)
   /* Wait 2 seconds.  */
   ts_timeout = timespec_add (ts_start, make_timespec (2, 0));
 
-  TEST_COMPARE (pthread_mutex_timedlock (&m, &ts_timeout), 0);
+  if (clockid == CLOCK_USE_TIMEDLOCK)
+    TEST_COMPARE (pthread_mutex_timedlock (&m, &ts_timeout), 0);
+  else
+    TEST_COMPARE (pthread_mutex_clocklock (&m, clockid, &ts_timeout), 0);
 
-  const struct timespec ts_end = xclock_now (CLOCK_REALTIME);
+  const struct timespec ts_end = xclock_now (clockid_for_get);
 
   /* Check that timedlock didn't delay.  We use a limit of 0.1 secs.  */
   TEST_TIMESPEC_BEFORE (ts_end,
@@ -93,4 +108,12 @@ do_test (void)
   return 0;
 }
 
+static int do_test (void)
+{
+  do_test_clock (CLOCK_USE_TIMEDLOCK, "timedlock");
+  do_test_clock (CLOCK_REALTIME, "clocklock(realtime)");
+  do_test_clock (CLOCK_MONOTONIC, "clocklock(monotonic)");
+  return 0;
+}
+
 #include <support/test-driver.c>
index e9fd8e2859497a778fa78f4cde185d286944238c..c0d218542fefa39b3d356ad76b7411833c8b03e5 100644 (file)
 #include <support/xunistd.h>
 
 
-static int
-do_test (void)
+/* A bogus clock value that tells run_test to use pthread_mutex_timedlock
+   rather than pthread_mutex_clocklock.  */
+#define CLOCK_USE_TIMEDLOCK (-1)
+
+static void
+do_test_clock (clockid_t clockid)
 {
+  const clockid_t clockid_for_get =
+    (clockid == CLOCK_USE_TIMEDLOCK) ? CLOCK_REALTIME : clockid;
   size_t ps = sysconf (_SC_PAGESIZE);
   char tmpfname[] = "/tmp/tst-mutex9.XXXXXX";
   char data[ps];
@@ -95,10 +101,13 @@ do_test (void)
       if (pthread_mutex_unlock (m) == 0)
         FAIL_EXIT1 ("child: mutex_unlock succeeded");
 
-      const struct timespec ts = timespec_add (xclock_now (CLOCK_REALTIME),
+      const struct timespec ts = timespec_add (xclock_now (clockid_for_get),
                                                make_timespec (0, 500000000));
 
-      TEST_COMPARE (pthread_mutex_timedlock (m, &ts), ETIMEDOUT);
+      if (clockid == CLOCK_USE_TIMEDLOCK)
+        TEST_COMPARE (pthread_mutex_timedlock (m, &ts), ETIMEDOUT);
+      else
+        TEST_COMPARE (pthread_mutex_clocklock (m, clockid, &ts), ETIMEDOUT);
 
       alarm (1);
 
@@ -117,7 +126,14 @@ do_test (void)
   if (! WIFSIGNALED (status))
     FAIL_EXIT1 ("child not killed by signal");
   TEST_COMPARE (WTERMSIG (status), SIGALRM);
+}
 
+static int
+do_test (void)
+{
+  do_test_clock (CLOCK_USE_TIMEDLOCK);
+  do_test_clock (CLOCK_REALTIME);
+  do_test_clock (CLOCK_MONOTONIC);
   return 0;
 }
 
index e78003eee48c72308babd2b43a7132be1e16ec7a..a767d6f18080301bb25dea9b7a67074ce5803bb8 100644 (file)
@@ -770,6 +770,13 @@ extern int pthread_mutex_timedlock (pthread_mutex_t *__restrict __mutex,
                                    __abstime) __THROWNL __nonnull ((1, 2));
 #endif
 
+#ifdef __USE_GNU
+extern int pthread_mutex_clocklock (pthread_mutex_t *__restrict __mutex,
+                                   clockid_t __clockid,
+                                   const struct timespec *__restrict
+                                   __abstime) __THROWNL __nonnull ((1, 3));
+#endif
+
 /* Unlock a mutex.  */
 extern int pthread_mutex_unlock (pthread_mutex_t *__mutex)
      __THROWNL __nonnull ((1));
index 9d9b2f7230e62aef28bd538089f496468ad7ea09..48c8e956bf686b6b72907cb71e018ff4008897e6 100644 (file)
@@ -242,6 +242,7 @@ GLIBC_2.28 tss_delete F
 GLIBC_2.28 tss_get F
 GLIBC_2.28 tss_set F
 GLIBC_2.30 pthread_cond_clockwait F
+GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
 GLIBC_2.30 pthread_rwlock_clockwrlock F
 GLIBC_2.30 sem_clockwait F
index 8f84762169f2500d7866906fa6fe38e3834e68da..d1912b159c43b5ff68e713e16a8449d901946192 100644 (file)
@@ -255,6 +255,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.30 pthread_cond_clockwait F
+GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
 GLIBC_2.30 pthread_rwlock_clockwrlock F
 GLIBC_2.30 sem_clockwait F
index 753209621e1e83fd3299c81eb4d159bde9f0281c..23d6f91363682a946d44dc11e72e9b8a7ee15956 100644 (file)
@@ -28,6 +28,7 @@ GLIBC_2.28 tss_delete F
 GLIBC_2.28 tss_get F
 GLIBC_2.28 tss_set F
 GLIBC_2.30 pthread_cond_clockwait F
+GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
 GLIBC_2.30 pthread_rwlock_clockwrlock F
 GLIBC_2.30 sem_clockwait F
index c3a183461a6de915fc39f0cdc407066f8fc46b46..52373fc28787e00394971e63a19f62db467b1193 100644 (file)
@@ -234,6 +234,7 @@ GLIBC_2.29 wait F
 GLIBC_2.29 waitpid F
 GLIBC_2.29 write F
 GLIBC_2.30 pthread_cond_clockwait F
+GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
 GLIBC_2.30 pthread_rwlock_clockwrlock F
 GLIBC_2.30 sem_clockwait F
index 5bfda37a867472a73b3376fcaeb896f5738357ee..71ff910bfd2c6adab1fbc91e4c8b3a00787c8de9 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.30 pthread_cond_clockwait F
+GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
 GLIBC_2.30 pthread_rwlock_clockwrlock F
 GLIBC_2.30 sem_clockwait F
index 321fec7b1328f43ccb67afbfb4a144fcc4c34e6c..e30d05dbb739def7bcea0af5b26c42d9f530eedb 100644 (file)
@@ -253,6 +253,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.30 pthread_cond_clockwait F
+GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
 GLIBC_2.30 pthread_rwlock_clockwrlock F
 GLIBC_2.30 sem_clockwait F
index fcef5b27c8fd2a16cbfd5febbb2e0a1684e011cf..0104488fda9ea8d5021e362ae17a8ae22eb879f0 100644 (file)
@@ -246,6 +246,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.30 pthread_cond_clockwait F
+GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
 GLIBC_2.30 pthread_rwlock_clockwrlock F
 GLIBC_2.30 sem_clockwait F
index 753209621e1e83fd3299c81eb4d159bde9f0281c..23d6f91363682a946d44dc11e72e9b8a7ee15956 100644 (file)
@@ -28,6 +28,7 @@ GLIBC_2.28 tss_delete F
 GLIBC_2.28 tss_get F
 GLIBC_2.28 tss_set F
 GLIBC_2.30 pthread_cond_clockwait F
+GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
 GLIBC_2.30 pthread_rwlock_clockwrlock F
 GLIBC_2.30 sem_clockwait F
index 321fec7b1328f43ccb67afbfb4a144fcc4c34e6c..e30d05dbb739def7bcea0af5b26c42d9f530eedb 100644 (file)
@@ -253,6 +253,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.30 pthread_cond_clockwait F
+GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
 GLIBC_2.30 pthread_rwlock_clockwrlock F
 GLIBC_2.30 sem_clockwait F
index e1d3cb44f4b2a141a87ac42797291dbc01dbb9b5..2e55810b02bbd14fe7ef191bbbc67fc0fd222876 100644 (file)
@@ -242,6 +242,7 @@ GLIBC_2.28 tss_delete F
 GLIBC_2.28 tss_get F
 GLIBC_2.28 tss_set F
 GLIBC_2.30 pthread_cond_clockwait F
+GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
 GLIBC_2.30 pthread_rwlock_clockwrlock F
 GLIBC_2.30 sem_clockwait F
index d1fb04308f524f25d91618d0a7d60b7786be518a..9aea7a96e9ecf90473b120b1b4a13afa38923283 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.30 pthread_cond_clockwait F
+GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
 GLIBC_2.30 pthread_rwlock_clockwrlock F
 GLIBC_2.30 sem_clockwait F
index d1fb04308f524f25d91618d0a7d60b7786be518a..9aea7a96e9ecf90473b120b1b4a13afa38923283 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.30 pthread_cond_clockwait F
+GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
 GLIBC_2.30 pthread_rwlock_clockwrlock F
 GLIBC_2.30 sem_clockwait F
index 3fae328f0680122a56123a1dafc177d74aeed348..0150ea362a3c7e690d3f834067e5c6051760a723 100644 (file)
@@ -242,6 +242,7 @@ GLIBC_2.28 tss_delete F
 GLIBC_2.28 tss_get F
 GLIBC_2.28 tss_set F
 GLIBC_2.30 pthread_cond_clockwait F
+GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
 GLIBC_2.30 pthread_rwlock_clockwrlock F
 GLIBC_2.30 sem_clockwait F
index 9f34536c648afab1d30b9b855f50585c133466fa..e958dc323395c83c9ea8022eb6a9ad0d521f88af 100644 (file)
@@ -255,6 +255,7 @@ GLIBC_2.3.4 pthread_setaffinity_np F
 GLIBC_2.3.4 pthread_setschedprio F
 GLIBC_2.3.4 siglongjmp F
 GLIBC_2.30 pthread_cond_clockwait F
+GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
 GLIBC_2.30 pthread_rwlock_clockwrlock F
 GLIBC_2.30 sem_clockwait F
index 9fb3fb63773480472351d14558d318092f1b55a6..ae1ffd1ac98c5471b4b551a1772f751aec38d252 100644 (file)
@@ -245,6 +245,7 @@ GLIBC_2.3.4 pthread_setaffinity_np F
 GLIBC_2.3.4 pthread_setschedprio F
 GLIBC_2.3.4 siglongjmp F
 GLIBC_2.30 pthread_cond_clockwait F
+GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
 GLIBC_2.30 pthread_rwlock_clockwrlock F
 GLIBC_2.30 sem_clockwait F
index 9d9b2f7230e62aef28bd538089f496468ad7ea09..48c8e956bf686b6b72907cb71e018ff4008897e6 100644 (file)
@@ -242,6 +242,7 @@ GLIBC_2.28 tss_delete F
 GLIBC_2.28 tss_get F
 GLIBC_2.28 tss_set F
 GLIBC_2.30 pthread_cond_clockwait F
+GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
 GLIBC_2.30 pthread_rwlock_clockwrlock F
 GLIBC_2.30 sem_clockwait F
index 83082fb74a9140a7fa9907239c9d631a715304a8..7dab4e5139deea595862734cdf3d63b0a5e0b4d8 100644 (file)
@@ -236,6 +236,7 @@ GLIBC_2.28 tss_delete F
 GLIBC_2.28 tss_get F
 GLIBC_2.28 tss_set F
 GLIBC_2.30 pthread_cond_clockwait F
+GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
 GLIBC_2.30 pthread_rwlock_clockwrlock F
 GLIBC_2.30 sem_clockwait F
index 94fc6ee0f3906b0f0489aaf7bb83647683aa26a0..841d8ef42ea690dc70f0bbf7d314b2bb115cf7e1 100644 (file)
@@ -255,6 +255,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.30 pthread_cond_clockwait F
+GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
 GLIBC_2.30 pthread_rwlock_clockwrlock F
 GLIBC_2.30 sem_clockwait F
index c26116248d776416a51f78ce4b24490b24d16494..ff3441c8ce3aa77c652319b704bb12598a4cabd2 100644 (file)
@@ -246,6 +246,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.30 pthread_cond_clockwait F
+GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
 GLIBC_2.30 pthread_rwlock_clockwrlock F
 GLIBC_2.30 sem_clockwait F
index 5bfda37a867472a73b3376fcaeb896f5738357ee..71ff910bfd2c6adab1fbc91e4c8b3a00787c8de9 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.30 pthread_cond_clockwait F
+GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
 GLIBC_2.30 pthread_rwlock_clockwrlock F
 GLIBC_2.30 sem_clockwait F
index 8f84762169f2500d7866906fa6fe38e3834e68da..d1912b159c43b5ff68e713e16a8449d901946192 100644 (file)
@@ -255,6 +255,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.30 pthread_cond_clockwait F
+GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
 GLIBC_2.30 pthread_rwlock_clockwrlock F
 GLIBC_2.30 sem_clockwait F
index fcef5b27c8fd2a16cbfd5febbb2e0a1684e011cf..0104488fda9ea8d5021e362ae17a8ae22eb879f0 100644 (file)
@@ -246,6 +246,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.30 pthread_cond_clockwait F
+GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
 GLIBC_2.30 pthread_rwlock_clockwrlock F
 GLIBC_2.30 sem_clockwait F
index a4072e53919ebaf3072c9ba29236e3da74e38879..297fec9686d2eceab0f0d31b73669e2ffd83f8d0 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.30 pthread_cond_clockwait F
+GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
 GLIBC_2.30 pthread_rwlock_clockwrlock F
 GLIBC_2.30 sem_clockwait F
index 45dc170c9d98ad6a48a7d794765c51bc9d6e8a54..1d04e63423a6894fbc8556328596794b3cd73e13 100644 (file)
@@ -242,6 +242,7 @@ GLIBC_2.28 tss_delete F
 GLIBC_2.28 tss_get F
 GLIBC_2.28 tss_set F
 GLIBC_2.30 pthread_cond_clockwait F
+GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
 GLIBC_2.30 pthread_rwlock_clockwrlock F
 GLIBC_2.30 sem_clockwait F