aboutsummaryrefslogtreecommitdiff
path: root/lib/libthr
diff options
context:
space:
mode:
authorMike Makonnen <mtm@FreeBSD.org>2004-01-29 09:44:36 +0000
committerMike Makonnen <mtm@FreeBSD.org>2004-01-29 09:44:36 +0000
commit98a11db62d676eed7710f4a06635d49092e00164 (patch)
treead5b9b25ae6d1419d325b325932ee757d75c1cd6 /lib/libthr
parente6e9fb749a5821ecd443d2350b2c510465af2ed4 (diff)
downloadsrc-98a11db62d676eed7710f4a06635d49092e00164.tar.gz
src-98a11db62d676eed7710f4a06635d49092e00164.zip
When suspending a thread if the timeout was very short or
the system call got interrupted and the absolute timeout is converted to a relative timeout, it may happen that we get a negative number. In such a case, simply set the timeout to zero so that if the event that the thread wants to wait for has happened it can still return successfully, but if it hasn't happened then the thread doesn't suspend indefinitely. This should fix certain applications (including mozilla) that seem to hang indefinitely sometimes. Noticed and debugged by: Morten Johansen <root@morten-johansen.net>
Notes
Notes: svn path=/head/; revision=125191
Diffstat (limited to 'lib/libthr')
-rw-r--r--lib/libthr/thread/thr_kern.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/libthr/thread/thr_kern.c b/lib/libthr/thread/thr_kern.c
index 3584246fddd9..1073ffdde289 100644
--- a/lib/libthr/thread/thr_kern.c
+++ b/lib/libthr/thread/thr_kern.c
@@ -137,6 +137,17 @@ _thread_suspend(pthread_t pthread, const struct timespec *abstime)
remaining = *abstime;
timespecsub(&remaining, &now);
ts = &remaining;
+
+ /*
+ * If the absolute timeout has already passed set the
+ * relative timeout to 0 sec. so that sigtimedwait()
+ * returns immediately.
+ * NOTE: timespecsub() makes sure the tv_nsec member >= 0.
+ */
+ if (ts->tv_sec < 0) {
+ ts->tv_sec = 0;
+ ts->tv_nsec = 0;
+ }
} else
ts = NULL;