]>
git.proxmox.com Git - wasi-libc.git/blob - libc-bottom-half/clocks/clock.c
1 #define _WASI_EMULATED_PROCESS_CLOCKS
4 #include <common/time.h>
7 CLOCKS_PER_SEC
== NSEC_PER_SEC
,
8 "This implementation assumes that `clock` is in nanoseconds"
11 // Snapshot of the monotonic clock at the start of the program.
12 static __wasi_timestamp_t start
;
14 // Use a priority of 10 to run fairly early in the implementation-reserved
15 // constructor priority range.
16 __attribute__((constructor(10)))
17 static void init(void) {
18 (void)__wasi_clock_time_get(__WASI_CLOCKID_MONOTONIC
, 0, &start
);
21 clock_t __clock(void) {
22 // Use `MONOTONIC` instead of `PROCESS_CPUTIME_ID` since WASI doesn't have
23 // an inherent concept of a process. Note that this means we'll incorrectly
24 // include time from other processes, so this function is only declared by
25 // the headers if `_WASI_EMULATED_PROCESS_CLOCKS` is defined.
26 __wasi_timestamp_t now
= 0;
27 (void)__wasi_clock_time_get(__WASI_CLOCKID_MONOTONIC
, 0, &now
);
31 __attribute__((__weak__
, __alias__("__clock")))