Source-Changes-HG archive

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

[src/trunk]: src/lib/libpthread Avoid passing zero-valued timespecs to timer_...



details:   https://anonhg.NetBSD.org/src/rev/fb0cb3d2366a
branches:  trunk
changeset: 572319:fb0cb3d2366a
user:      nathanw <nathanw%NetBSD.org@localhost>
date:      Wed Dec 29 20:47:39 2004 +0000

description:
Avoid passing zero-valued timespecs to timer_settime() when we want to set
a timer, as that will clear the timer instead. Pass in a safely in-the-past
value instead.
Addresses PR lib/28700.

(XXX passing in values between 0 and 1000 nanoseconds will still fail, but
 that bug needs to be fixed in timer_settime(), not here)

diffstat:

 lib/libpthread/pthread_alarms.c |  34 +++++++++++++++++++++++++++++-----
 1 files changed, 29 insertions(+), 5 deletions(-)

diffs (69 lines):

diff -r b05cb133b13b -r fb0cb3d2366a lib/libpthread/pthread_alarms.c
--- a/lib/libpthread/pthread_alarms.c   Wed Dec 29 20:34:11 2004 +0000
+++ b/lib/libpthread/pthread_alarms.c   Wed Dec 29 20:47:39 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pthread_alarms.c,v 1.10 2004/07/18 21:24:52 chs Exp $  */
+/*     $NetBSD: pthread_alarms.c,v 1.11 2004/12/29 20:47:39 nathanw Exp $      */
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: pthread_alarms.c,v 1.10 2004/07/18 21:24:52 chs Exp $");
+__RCSID("$NetBSD: pthread_alarms.c,v 1.11 2004/12/29 20:47:39 nathanw Exp $");
 
 #include <err.h>
 #include <sys/time.h>
@@ -97,7 +97,19 @@
        if (iterator == PTQ_FIRST(&pthread_alarmqueue)) {
                PTQ_INSERT_HEAD(&pthread_alarmqueue, alarm, pta_next);
                timespecclear(&it.it_interval);
-               it.it_value = *ts;
+               /*
+                * A zero-valued timespec will disarm the timer, but is
+                * a legitimate value for the _timedwait functions to
+                * pass in. Correct for this here and in other timer-resetting
+                * code by setting it_value to a small value that is
+                * safely in the past.
+                */
+               if (timespecisset(ts)) {
+                       it.it_value = *ts;
+               } else {
+                       it.it_value.tv_sec = 1;
+                       it.it_value.tv_nsec = 0;
+               }
                SDPRINTF(("(add %p) resetting alarm timer to %d.%06d\n",
                    self, it.it_value.tv_sec, it.it_value.tv_nsec/1000));
                retval = timer_settime(pthread_alarmtimer, TIMER_ABSTIME, 
@@ -127,7 +139,13 @@
                        next = PTQ_NEXT(alarm, pta_next);
                        timespecclear(&it.it_interval);
                        if (next != NULL)
-                               it.it_value = *next->pta_time;
+                               /* See comment in pthread__alarm_add() */
+                               if (timespecisset(next->pta_time)) {
+                                       it.it_value = *next->pta_time;
+                               } else {
+                                       it.it_value.tv_sec = 1;
+                                       it.it_value.tv_nsec = 0;
+                               }
                        else
                                timespecclear(&it.it_value);
                        SDPRINTF(("(del %p) resetting alarm timer to %d.%06d\n",
@@ -185,7 +203,13 @@
        /* 2. Reset the timer for the next element in the queue. */
        if (next) {
                timespecclear(&it.it_interval);
-               it.it_value = *next->pta_time;
+               /* See comment in pthread__alarm_add() */
+               if (timespecisset(next->pta_time)) {
+                       it.it_value = *next->pta_time;
+               } else {
+                       it.it_value.tv_sec = 1;
+                       it.it_value.tv_nsec = 0;
+               }
                SDPRINTF(("(pro %p) resetting alarm timer to %d.%09d\n", self,
                    it.it_value.tv_sec, it.it_value.tv_nsec));
                retval = timer_settime(pthread_alarmtimer, TIMER_ABSTIME, &it, NULL);



Home | Main Index | Thread Index | Old Index