Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-6]: src/lib/libpthread Pull up following revision(s) (requested b...



details:   https://anonhg.NetBSD.org/src/rev/07edff579bdf
branches:  netbsd-6
changeset: 775767:07edff579bdf
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Sat Apr 20 15:14:07 2013 +0000

description:
Pull up following revision(s) (requested by christos in ticket #862):
        lib/libpthread/pthread_cond.c: revision 1.60
        lib/libpthread/pthread_cond.c: revision 1.61
PR/47703: Yasushi Oshima: pthread_cond_timedwait() does not wait
after call pthread_condattr_setclock(CLOCK_MONOTONIC)
_lwp_park(2) expects a realtime clock, and it gets passed a monotonic
one.  Since monotonic < real, it never sleeps. This patch adjusts
the monotonic clock to be a real one before it passes is to
_lwp_park(2). This is the minimal hacky fix and it will be fixed
properly in _lwp_park(2) in the future.
XXX: pullup to 6.
for safety, declare mono on the outermost block it is used.

diffstat:

 lib/libpthread/pthread_cond.c |  28 ++++++++++++++++++++++++----
 1 files changed, 24 insertions(+), 4 deletions(-)

diffs (70 lines):

diff -r 9d7653b6904e -r 07edff579bdf lib/libpthread/pthread_cond.c
--- a/lib/libpthread/pthread_cond.c     Sat Apr 20 14:00:40 2013 +0000
+++ b/lib/libpthread/pthread_cond.c     Sat Apr 20 15:14:07 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pthread_cond.c,v 1.56.8.1 2012/11/28 23:47:37 riz Exp $        */
+/*     $NetBSD: pthread_cond.c,v 1.56.8.2 2013/04/20 15:14:07 bouyer Exp $     */
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -46,7 +46,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: pthread_cond.c,v 1.56.8.1 2012/11/28 23:47:37 riz Exp $");
+__RCSID("$NetBSD: pthread_cond.c,v 1.56.8.2 2013/04/20 15:14:07 bouyer Exp $");
 
 #include <errno.h>
 #include <sys/time.h>
@@ -74,6 +74,13 @@
 __strong_alias(__libc_cond_timedwait,pthread_cond_timedwait)
 __strong_alias(__libc_cond_destroy,pthread_cond_destroy)
 
+static clockid_t
+pthread_cond_getclock(const pthread_cond_t *cond)
+{
+       return cond->ptc_private ? 
+           *(clockid_t *)cond->ptc_private : CLOCK_REALTIME;
+}
+
 int
 pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
 {
@@ -119,6 +126,7 @@
 {
        pthread_t self;
        int retval;
+       struct timespec mono;
 
        pthread__error(EINVAL, "Invalid condition variable",
            cond->ptc_magic == _PT_COND_MAGIC);
@@ -127,6 +135,19 @@
        pthread__error(EPERM, "Mutex not locked in condition wait",
            mutex->ptm_owner != NULL);
        if (abstime != NULL) {
+               /*
+                * XXX: This should be done in the kernel to avoid
+                * extra system calls! 
+                */
+               if (pthread_cond_getclock(cond) == CLOCK_MONOTONIC) {
+                       struct timespec real;
+                       if (clock_gettime(CLOCK_REALTIME, &real) == -1 ||
+                           clock_gettime(CLOCK_MONOTONIC, &mono) == -1)
+                               return errno;
+                       timespecsub(abstime, &mono, &mono);
+                       timespecadd(&mono, &real, &mono);
+                       abstime = &mono;
+               }
                pthread__error(EINVAL, "Invalid wait time", 
                    (abstime->tv_sec >= 0) &&
                    (abstime->tv_nsec >= 0) &&
@@ -375,8 +396,7 @@
                diff.tv_sec = 99999999;
                diff.tv_nsec = 0;
        } else {
-               clockid_t clck = cond->ptc_private ?
-                   *(clockid_t *)cond->ptc_private : CLOCK_REALTIME;
+               clockid_t clck = pthread_cond_getclock(cond);
                clock_gettime(clck, &now);
                if  (timespeccmp(abstime, &now, <))
                        timespecclear(&diff);



Home | Main Index | Thread Index | Old Index