summaryrefslogtreecommitdiffstats
path: root/thread.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-07-30 08:48:31 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-07-30 08:48:31 +0000
commit5b765f11580ed4325688357cdce00644cb9782c5 (patch)
treef731aae993a5b87d2c48b64d4d5b1786c87eba29 /thread.c
parent33d5fdaa6a219b9b8dd9757936397eb3a4ef926c (diff)
downloadruby-5b765f11580ed4325688357cdce00644cb9782c5.tar.gz
ruby-5b765f11580ed4325688357cdce00644cb9782c5.tar.xz
ruby-5b765f11580ed4325688357cdce00644cb9782c5.zip
* win32/win32.c (rb_w32_select): recalc the rest of timeout for each
iterations. [ruby-core:18015] git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@18262 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread.c')
-rw-r--r--thread.c29
1 files changed, 24 insertions, 5 deletions
diff --git a/thread.c b/thread.c
index c25e8b1f6..f6e7ff279 100644
--- a/thread.c
+++ b/thread.c
@@ -1957,7 +1957,7 @@ cmp_tv(const struct timeval *a, const struct timeval *b)
}
static int
-subst(struct timeval *rest, const struct timeval *wait)
+subtract_tv(struct timeval *rest, const struct timeval *wait)
{
while (rest->tv_usec < wait->tv_usec) {
if (rest->tv_sec <= wait->tv_sec) {
@@ -1982,10 +1982,18 @@ do_select(int n, fd_set *read, fd_set *write, fd_set *except,
#ifndef linux
double limit = 0;
struct timeval wait_rest;
+# if defined(__CYGWIN__) || defined(_WIN32)
+ struct timeval start_time;
+# endif
if (timeout) {
- limit = timeofday() +
- (double)timeout->tv_sec+(double)timeout->tv_usec*1e-6;
+# if defined(__CYGWIN__) || defined(_WIN32)
+ gettimeofday(&start_time, NULL);
+ limit = (double)start_time.tv_sec + (double)start_time.tv_usec*1e-6;
+# else
+ limit = timeofday();
+# endif
+ limit += (double)timeout->tv_sec+(double)timeout->tv_usec*1e-6;
wait_rest = *timeout;
timeout = &wait_rest;
}
@@ -2000,6 +2008,7 @@ do_select(int n, fd_set *read, fd_set *write, fd_set *except,
#if defined(__CYGWIN__) || defined(_WIN32)
{
+ int finish = 0;
/* polling duration: 100ms */
struct timeval wait_100ms, *wait;
wait_100ms.tv_sec = 0;
@@ -2017,9 +2026,19 @@ do_select(int n, fd_set *read, fd_set *write, fd_set *except,
if (write) *write = orig_write;
if (except) *except = orig_except;
wait = &wait_100ms;
- } while (__th->interrupt_flag == 0 && (timeout == 0 || subst(timeout, &wait_100ms)));
+ if (timeout) {
+ struct timeval elapsed;
+ gettimeofday(&elapsed, NULL);
+ subtract_tv(&elapsed, &start_time);
+ if (!subtract_tv(timeout, &elapsed)) {
+ finish = 1;
+ break;
+ }
+ if (cmp_tv(&wait_100ms, timeout) < 0) wait = timeout;
+ }
+ } while (__th->interrupt_flag == 0);
}, 0, 0);
- } while (result == 0 && (timeout == 0 || subst(timeout, &wait_100ms)));
+ } while (result == 0 && !finish);
}
#else
BLOCKING_REGION({