Mercurial > hg > Members > anatofuz > MoarVM
view src/platform/win32/time.c @ 4:352169b06523
update
author | Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 05 Oct 2018 19:31:02 +0900 |
parents | 2cf249471370 |
children |
line wrap: on
line source
#include "moar.h" #include "platform/time.h" #include <windows.h> /* see http://support.microsoft.com/kb/167296 */ #define OFFSET 116444736000000000 #define E6 1000000 MVMuint64 MVM_platform_now(void) { union { FILETIME ft; MVMuint64 u; } now; GetSystemTimeAsFileTime(&now.ft); return (now.u - OFFSET) * 100; } void MVM_platform_sleep(MVMnum64 second) { DWORD millis = (DWORD)(second * 1000); Sleep(millis); } void MVM_platform_nanosleep(MVMuint64 nanos) { MVMuint64 now; DWORD millis; const MVMuint64 end = MVM_platform_now() + nanos; millis = (DWORD)((nanos + E6 - 1) / E6); while(1) { Sleep(millis); now = MVM_platform_now(); if (now >= end) break; millis = (DWORD)((end - now) / E6); } }