diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-07-30 08:48:31 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-07-30 08:48:31 +0000 |
commit | 807fcf9d13fbb30773944cde4f18f11b0a26a8a7 (patch) | |
tree | f731aae993a5b87d2c48b64d4d5b1786c87eba29 /thread.c | |
parent | be9994a03ae32b5cd4a799b20ed96c3aaaba97b7 (diff) |
* win32/win32.c (rb_w32_select): recalc the rest of timeout for each
iterations. [ruby-core:18015]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18262 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread.c')
-rw-r--r-- | thread.c | 29 |
1 files changed, 24 insertions, 5 deletions
@@ -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({ |