From 977b7cbf371b5b005e14cbd141c59282c52e9893 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 23 Jun 2020 12:34:16 -0400 Subject: [PATCH] add jtk.time module --- src/jtk/jtk.c | 25 +++++++++++++++++++++++++ src/jtk/package.d | 1 + src/jtk/time.d | 13 +++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 src/jtk/time.d diff --git a/src/jtk/jtk.c b/src/jtk/jtk.c index 7007d26..3562e9c 100644 --- a/src/jtk/jtk.c +++ b/src/jtk/jtk.c @@ -4,12 +4,17 @@ #include #include #include +#include static Display * g_display; static XVisualInfo * g_vi; static XSetWindowAttributes g_swa; static GLXContext g_context; +/************************************************************************** + * Init + *************************************************************************/ + /** * Initialize the Jtk subsystem. * @@ -56,6 +61,26 @@ bool jtk_init() return true; } +/************************************************************************** + * Time + *************************************************************************/ + +/** + * Get system time in microseconds. + * + * @return System time in microseconds. + */ +uint64_t jtk_us_time() +{ + struct timeval tv; + gettimeofday(&tv, NULL); + return (uint64_t)tv.tv_sec * 1000000u + (uint64_t)tv.tv_usec; +} + +/************************************************************************** + * Window + *************************************************************************/ + static Bool wait_for_notify(Display * display, XEvent * event, XPointer arg) { return (event->type == MapNotify) && (event->xmap.window == (Window)arg); diff --git a/src/jtk/package.d b/src/jtk/package.d index 6b1c35f..6acfb83 100644 --- a/src/jtk/package.d +++ b/src/jtk/package.d @@ -2,4 +2,5 @@ module jtk; public import jtk.event; public import jtk.init; +public import jtk.time; public import jtk.window; diff --git a/src/jtk/time.d b/src/jtk/time.d new file mode 100644 index 0000000..29c6deb --- /dev/null +++ b/src/jtk/time.d @@ -0,0 +1,13 @@ +module jtk.time; + +private extern(C) ulong jtk_us_time(); + +ulong us_time() +{ + return jtk_us_time(); +} + +ulong ms_time() +{ + return us_time() / 1000u; +}