summaryrefslogtreecommitdiff
path: root/thread_win32.c
diff options
context:
space:
mode:
authorkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-06 17:39:32 +0000
committerkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-06 17:39:32 +0000
commitb2ea836ae705cc690d1230476e6eb97e92e7ef52 (patch)
treeac115f6899ebd605a36aee02d976e29b6dad7f79 /thread_win32.c
parent54b50fbb9c5a62a5dbefc40568985b23eb4d1238 (diff)
mutex: deadlock check timeout use monotonic time.
* thread_pthread.c (native_cond_timeout): new internal api. it calculate a proper time for argument of native_cond_timedwait(). * thread_win32.c (native_cond_timeout): ditto. * thread_pthread.c (thread_timer): use native_cond_timeout() instead of get_ts. * thread.c (lock_func): ditto. * thread_pthread.c (get_ts): removed. use native_cond_timeout(). * thread.c (init_lock_timeout): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31454 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread_win32.c')
-rw-r--r--thread_win32.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/thread_win32.c b/thread_win32.c
index 287f637911..62f78fd850 100644
--- a/thread_win32.c
+++ b/thread_win32.c
@@ -489,6 +489,29 @@ native_cond_timedwait(rb_thread_cond_t *cond, rb_thread_lock_t *mutex, struct ti
return __cond_timedwait(cond, mutex, timeout_ms);
}
+static struct timespec
+native_cond_timeout(rb_thread_cond_t *cond, struct timespec timeout_rel)
+{
+ int ret;
+ struct timeval tv;
+ struct timespec timeout;
+
+ ret = gettimeofday(&tv, 0);
+ if (ret != 0)
+ rb_sys_fail(0);
+ timeout.tv_sec = tv.tv_sec;
+ timeout.tv_nsec = tv.tv_usec * 1000;
+
+ timeout.tv_sec += timeout_rel.tv_sec;
+ timeout.tv_nsec += timeout_rel.tv_nsec;
+ if (timeout.tv_nsec >= 1000*1000*1000) {
+ timeout.tv_sec++;
+ timeout.tv_nsec -= 1000*1000*1000;
+ }
+ return timeout;
+}
+
+
static void
native_cond_initialize(rb_thread_cond_t *cond, int flags)
{