summaryrefslogtreecommitdiff
path: root/thread_win32.c
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-08-25 06:58:35 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-08-25 06:58:35 +0000
commitb0253a7569ffbf58fd3a61500aacd7369cce36dd (patch)
treee346ca1c7085143ad0ba9f1d167d1fe4b5ce394c /thread_win32.c
parent7c31c2738c7d02e5a9ac6167c650cb8a5411321d (diff)
thread.c: use rb_hrtime_t scalar for high-resolution time operations
Relying on "struct timespec" was too annoying API-wise and used more stack space. "double" was a bit wacky w.r.t rounding in the past, so now we'll switch to using a 64-bit type. Unsigned 64-bit integer is able to give us over nearly 585 years of range with nanoseconds. This range is good enough for the Linux kernel internal time representation, so it ought to be good enough for us. This reduces the stack usage of functions while GVL is held (and thus subject to marking) on x86-64 Linux (with ppoll): rb_wait_for_single_fd 120 => 104 do_select 120 => 88 [ruby-core:88582] [Misc #15014] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64533 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread_win32.c')
-rw-r--r--thread_win32.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/thread_win32.c b/thread_win32.c
index af9d3517fa..83896d81ff 100644
--- a/thread_win32.c
+++ b/thread_win32.c
@@ -276,11 +276,16 @@ rb_w32_Sleep(unsigned long msec)
return ret;
}
+static DWORD
+hrtime2msec(rb_hrtime_t hrt)
+{
+ return (DWORD)hrt / (DWORD)RB_HRTIME_PER_MSEC;
+}
+
static void
-native_sleep(rb_thread_t *th, struct timespec *ts)
+native_sleep(rb_thread_t *th, rb_hrtime_t *rel)
{
- const volatile DWORD msec = (ts) ?
- (DWORD)(ts->tv_sec * 1000 + ts->tv_nsec / 1000000) : INFINITE;
+ const volatile DWORD msec = rel ? hrtime2msec(*rel) : INFINITE;
GVL_UNLOCK_BEGIN(th);
{