1
0
mirror of https://github.com/janet-lang/janet synced 2024-09-28 15:08:40 +00:00

Try again with os.clock.

This commit is contained in:
Calvin Rose 2018-07-08 21:10:15 -04:00
parent 5b15ad9ff8
commit f232cf28ff
2 changed files with 7 additions and 9 deletions

View File

@ -2,6 +2,7 @@ version: 1.0.{build}
branches: branches:
only: only:
- master - master
- alpha
clone_folder: c:\projects\dst clone_folder: c:\projects\dst
image: image:
- Visual Studio 2017 - Visual Studio 2017

View File

@ -197,26 +197,23 @@ static int os_exit(DstArgs args) {
/* Clock shim for windows */ /* Clock shim for windows */
#ifdef DST_WINDOWS #ifdef DST_WINDOWS
struct timespec {
long tv_sec;
long tv_nsec;
};
static int clock_gettime(int, struct timespec *spec) { static int clock_gettime(int, struct timespec *spec) {
int64_t wintime; int64_t wintime = 0LL;
GetSystemTimeAsFileTime((FILETIME*)&wintime); GetSystemTimeAsFileTime((FILETIME*)&wintime);
wintime -= 116444736000000000LL; /* Windows epic is 1601, jan 1 */ /* Windows epoch is January 1, 1601 apparently*/
wintime -= 116444736000000000LL;
spec->tv_sec = wintime / 10000000LL; spec->tv_sec = wintime / 10000000LL;
/* Resolution is 100 nanoseconds. */ /* Resolution is 100 nanoseconds. */
spec->tv_nsec = wintime % 10000000LL * 100; spec->tv_nsec = wintime % 10000000LL * 100;
return 0; return 0;
} }
#define CLOCK_REALTIME 0 #define CLOCK_MONOTONIC 0
#endif #endif
static int os_clock(DstArgs args) { static int os_clock(DstArgs args) {
DST_FIXARITY(args, 0); DST_FIXARITY(args, 0);
struct timespec tv; struct timespec tv;
if (clock_gettime(CLOCK_REALTIME, &tv)) if (clock_gettime(CLOCK_MONOTONIC, &tv))
DST_THROW(args, "could not get time"); DST_THROW(args, "could not get time");
double dtime = tv.tv_sec + (tv.tv_nsec / 1E9); double dtime = tv.tv_sec + (tv.tv_nsec / 1E9);
DST_RETURN_REAL(args, dtime); DST_RETURN_REAL(args, dtime);