unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Mike Crowe <mac@mcrowe.com>
To: libc-alpha@sourceware.org
Cc: Mike Crowe <mac@mcrowe.com>
Subject: [PATCH 4/7] nptl: pthread_rwlock: Move timeout validation into _full functions
Date: Wed, 27 Feb 2019 18:23:54 +0000	[thread overview]
Message-ID: <5292325009aa674d78d114d85bdbce94c3aec909.1551291557.git-series.mac@mcrowe.com> (raw)
In-Reply-To: <cover.b0c66849a87ca79889a49f2f1f2563b1a8a15d8b.1551291557.git-series.mac@mcrowe.com>
In-Reply-To: <cover.b0c66849a87ca79889a49f2f1f2563b1a8a15d8b.1551291557.git-series.mac@mcrowe.com>

As recommended by the comments in the implementations of
pthread_rwlock_timedrdlock and pthread_rwlock_timedwrlock, let's move the
timeout validity checks into the corresponding pthread_rwlock_rdlock_full
and pthread_rwlock_wrlock_full functions. Since these functions may be
called with abstime == NULL, an extra check for that is necessary too.
---
 nptl/pthread_rwlock_common.c      | 20 ++++++++++++++++++++
 nptl/pthread_rwlock_timedrdlock.c | 10 ----------
 nptl/pthread_rwlock_timedwrlock.c | 10 ----------
 3 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/nptl/pthread_rwlock_common.c b/nptl/pthread_rwlock_common.c
index 89ba21a..120b880 100644
--- a/nptl/pthread_rwlock_common.c
+++ b/nptl/pthread_rwlock_common.c
@@ -282,6 +282,16 @@ __pthread_rwlock_rdlock_full (pthread_rwlock_t *rwlock,
 {
   unsigned int r;
 
+  /* Make sure any passed in timeout value is valid.  Note that the previous
+     implementation assumed that this check *must* not be performed if there
+     would in fact be no blocking; however, POSIX only requires that "the
+     validity of the abstime parameter need not be checked if the lock can be
+     immediately acquired" (i.e., we need not but may check it).  */
+  if (abstime
+      && __glibc_unlikely (abstime->tv_nsec >= 1000000000
+      || abstime->tv_nsec < 0))
+    return EINVAL;
+
   /* Make sure we are not holding the rwlock as a writer.  This is a deadlock
      situation we recognize and report.  */
   if (__glibc_unlikely (atomic_load_relaxed (&rwlock->__data.__cur_writer)
@@ -576,6 +586,16 @@ static __always_inline int
 __pthread_rwlock_wrlock_full (pthread_rwlock_t *rwlock,
     const struct timespec *abstime)
 {
+  /* Make sure any passed in timeout value is valid.  Note that the previous
+     implementation assumed that this check *must* not be performed if there
+     would in fact be no blocking; however, POSIX only requires that "the
+     validity of the abstime parameter need not be checked if the lock can be
+     immediately acquired" (i.e., we need not but may check it).  */
+  if (abstime
+      && __glibc_unlikely (abstime->tv_nsec >= 1000000000
+      || abstime->tv_nsec < 0))
+    return EINVAL;
+
   /* Make sure we are not holding the rwlock as a writer.  This is a deadlock
      situation we recognize and report.  */
   if (__glibc_unlikely (atomic_load_relaxed (&rwlock->__data.__cur_writer)
diff --git a/nptl/pthread_rwlock_timedrdlock.c b/nptl/pthread_rwlock_timedrdlock.c
index aa00530..84c1983 100644
--- a/nptl/pthread_rwlock_timedrdlock.c
+++ b/nptl/pthread_rwlock_timedrdlock.c
@@ -23,15 +23,5 @@ int
 pthread_rwlock_timedrdlock (pthread_rwlock_t *rwlock,
     const struct timespec *abstime)
 {
-  /* Make sure the passed in timeout value is valid.  Note that the previous
-     implementation assumed that this check *must* not be performed if there
-     would in fact be no blocking; however, POSIX only requires that "the
-     validity of the abstime parameter need not be checked if the lock can be
-     immediately acquired" (i.e., we need not but may check it).  */
-  /* ??? Just move this to __pthread_rwlock_rdlock_full?  */
-  if (__glibc_unlikely (abstime->tv_nsec >= 1000000000
-      || abstime->tv_nsec < 0))
-    return EINVAL;
-
   return __pthread_rwlock_rdlock_full (rwlock, abstime);
 }
diff --git a/nptl/pthread_rwlock_timedwrlock.c b/nptl/pthread_rwlock_timedwrlock.c
index 3c92e44..f0b745d 100644
--- a/nptl/pthread_rwlock_timedwrlock.c
+++ b/nptl/pthread_rwlock_timedwrlock.c
@@ -23,15 +23,5 @@ int
 pthread_rwlock_timedwrlock (pthread_rwlock_t *rwlock,
     const struct timespec *abstime)
 {
-  /* Make sure the passed in timeout value is valid.  Note that the previous
-     implementation assumed that this check *must* not be performed if there
-     would in fact be no blocking; however, POSIX only requires that "the
-     validity of the abstime parameter need not be checked if the lock can be
-     immediately acquired" (i.e., we need not but may check it).  */
-  /* ??? Just move this to __pthread_rwlock_wrlock_full?  */
-  if (__glibc_unlikely (abstime->tv_nsec >= 1000000000
-      || abstime->tv_nsec < 0))
-    return EINVAL;
-
   return __pthread_rwlock_wrlock_full (rwlock, abstime);
 }
-- 
git-series 0.9.1

  parent reply	other threads:[~2019-02-27 18:25 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-27 18:23 [PATCH 0/7] Implement proposed POSIX _clockwait variants of existing _timedwait functions Mike Crowe
2019-02-27 18:23 ` [PATCH 1/7] nptl: Add clockid parameter to futex timed wait calls Mike Crowe
2019-03-05 12:39   ` Adhemerval Zanella
2019-03-10  8:59     ` Mike Crowe
2019-03-11 11:50       ` Adhemerval Zanella
2019-02-27 18:23 ` [PATCH 2/7] nptl: Add POSIX-proposed sem_clockwait Mike Crowe
2019-02-27 18:35   ` Joseph Myers
2019-03-05 13:31   ` Adhemerval Zanella
2019-03-10 16:17     ` Mike Crowe
2019-03-19 17:07       ` Adhemerval Zanella
2019-03-14 14:09   ` Yann Droneaud
2019-03-14 14:39     ` Mike Crowe
2019-02-27 18:23 ` [PATCH 3/7] nptl: Add POSIX-proposed pthread_cond_clockwait Mike Crowe
2019-03-05 16:45   ` Adhemerval Zanella
2019-05-04 20:22     ` Mike Crowe
2019-02-27 18:23 ` Mike Crowe [this message]
2019-03-05 16:48   ` [PATCH 4/7] nptl: pthread_rwlock: Move timeout validation into _full functions Adhemerval Zanella
2019-02-27 18:23 ` [PATCH 5/7] nptl/tst-rwlock14: Test pthread/rwlock_timedwrlock correctly Mike Crowe
2019-03-05 17:36   ` Adhemerval Zanella
2019-02-27 18:23 ` [PATCH 6/7] nptl/tst-rwlock: Use clock_gettime/timespec rather than gettimeofday/timeval Mike Crowe
2019-03-05 18:02   ` Adhemerval Zanella
2019-03-20 21:34     ` Mike Crowe
2019-03-14 14:44   ` Yann Droneaud
2019-02-27 18:23 ` [PATCH 7/7] nptl: Add POSIX-proposed pthread_rwlock_clockrdlock & pthread_rwlock_clockwrlock Mike Crowe
2019-03-07 12:59   ` Adhemerval Zanella
2019-03-05 12:35 ` [PATCH 0/7] Implement proposed POSIX _clockwait variants of existing _timedwait functions Adhemerval Zanella
2019-03-06 21:15   ` Joseph Myers
2019-03-10  9:12     ` Mike Crowe
2019-03-11 23:13       ` Joseph Myers
2019-03-13 21:42   ` Mike Crowe
2019-03-14 11:30     ` Adhemerval Zanella
2019-03-15 13:25 ` Yann Droneaud
2019-03-15 13:36   ` Mike Crowe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/libc/involved.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5292325009aa674d78d114d85bdbce94c3aec909.1551291557.git-series.mac@mcrowe.com \
    --to=mac@mcrowe.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).