summaryrefslogtreecommitdiff
path: root/thread.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-07-10 03:09:23 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-07-10 03:09:23 +0000
commit7ad9faa5280b0f6e87ef658bc209ffe24fdac85c (patch)
tree53ad2c1626b00fc70d41214c3b8fa8b0ffde2e58 /thread.c
parenta0e291f697a198c6be1d0b73f4c1b57edb924982 (diff)
* thread.c (rb_thread_wait_for): wait until timed out only when
sleeping with timeout. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17984 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread.c')
-rw-r--r--thread.c48
1 files changed, 24 insertions, 24 deletions
diff --git a/thread.c b/thread.c
index 50748a8e14..3bee915cfb 100644
--- a/thread.c
+++ b/thread.c
@@ -736,29 +736,7 @@ getclockofday(struct timeval *tp)
static void
sleep_timeval(rb_thread_t *th, struct timeval tv)
{
- struct timeval to, tvn;
-
- getclockofday(&to);
- to.tv_sec += tv.tv_sec;
- if ((to.tv_usec += tv.tv_usec) >= 1000000) {
- to.tv_sec++;
- to.tv_usec -= 1000000;
- }
-
- for (;;) {
- native_sleep(th, &tv, 0);
- getclockofday(&tvn);
- if (to.tv_sec < tvn.tv_sec) break;
- if (to.tv_sec == tvn.tv_sec && to.tv_usec <= tvn.tv_usec) break;
- thread_debug("sleep_timeval: %ld.%.6ld > %ld.%.6ld\n",
- (long)to.tv_sec, to.tv_usec,
- (long)tvn.tv_sec, tvn.tv_usec);
- tv.tv_sec = to.tv_sec - tvn.tv_sec;
- if ((tv.tv_usec = to.tv_usec - tvn.tv_usec) < 0) {
- --tv.tv_sec;
- tv.tv_usec += 1000000;
- }
- }
+ native_sleep(th, &tv, 0);
}
void
@@ -811,7 +789,29 @@ void
rb_thread_wait_for(struct timeval time)
{
rb_thread_t *th = GET_THREAD();
- sleep_timeval(th, time);
+ struct timeval to, tvn;
+
+ getclockofday(&to);
+ to.tv_sec += tv.tv_sec;
+ if ((to.tv_usec += tv.tv_usec) >= 1000000) {
+ to.tv_sec++;
+ to.tv_usec -= 1000000;
+ }
+
+ for (;;) {
+ sleep_timeval(th, time);
+ getclockofday(&tvn);
+ if (to.tv_sec < tvn.tv_sec) break;
+ if (to.tv_sec == tvn.tv_sec && to.tv_usec <= tvn.tv_usec) break;
+ thread_debug("sleep_timeval: %ld.%.6ld > %ld.%.6ld\n",
+ (long)to.tv_sec, to.tv_usec,
+ (long)tvn.tv_sec, tvn.tv_usec);
+ tv.tv_sec = to.tv_sec - tvn.tv_sec;
+ if ((tv.tv_usec = to.tv_usec - tvn.tv_usec) < 0) {
+ --tv.tv_sec;
+ tv.tv_usec += 1000000;
+ }
+ }
}
void