glibc/nptl/tst-abstime.c
Mike Crowe 9d20e22e46 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>
2019-07-12 13:36:25 +00:00

74 lines
2.5 KiB
C

/* Copyright (C) 2010-2019 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Andreas Schwab <schwab@redhat.com>, 2010.
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 <semaphore.h>
#include <stdio.h>
#include <support/check.h>
#include <support/xthread.h>
static pthread_cond_t c = PTHREAD_COND_INITIALIZER;
static pthread_mutex_t m1 = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t m2 = PTHREAD_MUTEX_INITIALIZER;
static pthread_rwlock_t rw1 = PTHREAD_RWLOCK_INITIALIZER;
static pthread_rwlock_t rw2 = PTHREAD_RWLOCK_INITIALIZER;
static sem_t sem;
static void *
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),
ETIMEDOUT);
TEST_COMPARE (pthread_rwlock_clockwrlock (&rw2, CLOCK_REALTIME, &t),
ETIMEDOUT);
TEST_COMPARE (pthread_rwlock_clockrdlock (&rw1, CLOCK_MONOTONIC, &t),
ETIMEDOUT);
TEST_COMPARE (pthread_rwlock_clockwrlock (&rw2, CLOCK_MONOTONIC, &t),
ETIMEDOUT);
return NULL;
}
static int
do_test (void)
{
struct timespec t = { -2, 0 };
sem_init (&sem, 0, 0);
TEST_COMPARE (sem_timedwait (&sem, &t), -1);
TEST_COMPARE (errno, ETIMEDOUT);
xpthread_mutex_lock (&m1);
xpthread_rwlock_wrlock (&rw1);
xpthread_rwlock_rdlock (&rw2);
xpthread_mutex_lock (&m2);
pthread_t pth = xpthread_create (0, th, 0);
TEST_COMPARE (pthread_cond_timedwait (&c, &m2, &t), ETIMEDOUT);
xpthread_join (pth);
return 0;
}
#include <support/test-driver.c>