diff options
Diffstat (limited to 'std/time.zc')
| -rw-r--r-- | std/time.zc | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/std/time.zc b/std/time.zc new file mode 100644 index 0000000..72e611a --- /dev/null +++ b/std/time.zc @@ -0,0 +1,44 @@ + +import "./core.zc" + +raw { + #include <time.h> + #include <unistd.h> + #include <sys/time.h> + + static uint64_t _time_now_impl(void) { + struct timeval tv; + gettimeofday(&tv, NULL); + return (uint64_t)(tv.tv_sec) * 1000 + (uint64_t)(tv.tv_usec) / 1000; + } +} + +struct Duration { + millis: U64; +} + +impl Duration { + fn from_ms(ms: U64) -> Duration { + return Duration { millis: ms }; + } + + fn from_secs(s: U64) -> Duration { + return Duration { millis: s * (U64)1000 }; + } +} + +struct Time {} + +impl Time { + fn now() -> U64 { + return _time_now_impl(); + } + + fn sleep(d: Duration) { + usleep((U32)(d.millis * (U64)1000)); + } + + fn sleep_ms(ms: U64) { + usleep((U32)(ms * (U64)1000)); + } +} |
