mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-23 01:33:36 +08:00
nptl: Add POSIX-proposed pthread_mutex_clocklock
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>
This commit is contained in:
parent
59213094c8
commit
9d20e22e46
76
ChangeLog
76
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
|
||||
|
@ -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
|
||||
|
@ -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 \
|
||||
|
@ -279,6 +279,7 @@ libpthread {
|
||||
GLIBC_2.30 {
|
||||
sem_clockwait; pthread_cond_clockwait;
|
||||
pthread_rwlock_clockrdlock; pthread_rwlock_clockwrlock;
|
||||
pthread_mutex_clocklock;
|
||||
}
|
||||
|
||||
GLIBC_PRIVATE {
|
||||
|
@ -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);
|
||||
|
@ -42,15 +42,14 @@
|
||||
#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)
|
||||
|
@ -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),
|
||||
|
69
nptl/tst-mutex11.c
Normal file
69
nptl/tst-mutex11.c
Normal file
@ -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>
|
@ -32,12 +32,17 @@
|
||||
# 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>
|
||||
|
@ -31,9 +31,15 @@
|
||||
#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;
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user