ascii-chat 0.11.33
Video chat in your terminal
Loading...
Searching...
No Matches
platform/wasm/time.c
Go to the documentation of this file.
1
8#include <time.h>
9#include <sys/time.h>
10#include <stdint.h>
11
13 struct timeval tv;
14 gettimeofday(&tv, NULL);
15 return (uint64_t)tv.tv_sec * 1000 + (uint64_t)tv.tv_usec / 1000;
16}
17
19 struct timeval tv;
20 gettimeofday(&tv, NULL);
21 return (uint64_t)tv.tv_sec * 1000000 + (uint64_t)tv.tv_usec;
22}
23
24void platform_sleep_ms(unsigned int ms) {
25 struct timespec ts;
26 ts.tv_sec = ms / 1000;
27 ts.tv_nsec = (ms % 1000) * 1000000;
28 nanosleep(&ts, NULL);
29}
30
31void platform_sleep_us(unsigned int us) {
32 struct timespec ts;
33 ts.tv_sec = us / 1000000;
34 ts.tv_nsec = (us % 1000000) * 1000;
35 nanosleep(&ts, NULL);
36}
37
39 struct timespec ts;
40 clock_gettime(CLOCK_MONOTONIC, &ts);
41 return (uint64_t)ts.tv_sec * 1000000000ULL + (uint64_t)ts.tv_nsec;
42}
43
45 struct timespec ts;
46 clock_gettime(CLOCK_MONOTONIC, &ts);
47 return (uint64_t)ts.tv_sec * 1000000ULL + (uint64_t)ts.tv_nsec / 1000ULL;
48}
49
51 struct timespec ts;
52 ts.tv_sec = ns / 1000000000ULL;
53 ts.tv_nsec = ns % 1000000000ULL;
54 nanosleep(&ts, NULL);
55}
Platform abstraction layer umbrella header providing unified cross-platform API.
unsigned long long uint64_t
Definition common.h:59
void platform_sleep_ns(uint64_t ns)
Platform-safe sleep function with nanosecond precision.
uint64_t platform_get_monotonic_time_us(void)
Get monotonic time in microseconds.
void platform_sleep_ms(unsigned int ms)
Sleep for a specified number of milliseconds.
void platform_sleep_us(unsigned int us)
High-precision sleep function with microsecond precision.
uint64_t platform_get_time_ms(void)
uint64_t platform_get_time_us(void)
uint64_t platform_get_monotonic_time_ns(void)
⏱️ High-precision timing utilities using sokol_time.h and uthash