forked from bminor/glibc
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nptl: Add POSIX-proposed sem_clockwait
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 <[email protected]>
- Loading branch information
Showing
36 changed files
with
293 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,64 @@ | ||
2019-07-12 Mike Crowe <[email protected]> | ||
|
||
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
Oops, something went wrong.