ascii-chat 0.8.38
Real-time terminal-based video chat with ASCII art conversion
Loading...
Searching...
No Matches
platform/wasm/time.c
Go to the documentation of this file.
1
7#include <ascii-chat/platform/abstraction.h>
8#include <time.h>
9#include <sys/time.h>
10#include <stdint.h>
11
12uint64_t platform_get_time_ms(void) {
13 struct timeval tv;
14 gettimeofday(&tv, NULL);
15 return (uint64_t)tv.tv_sec * 1000 + (uint64_t)tv.tv_usec / 1000;
16}
17
18uint64_t platform_get_time_us(void) {
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}
uint64_t platform_get_time_ms(void)
void platform_sleep_us(unsigned int us)
uint64_t platform_get_monotonic_time_us(void)
uint64_t platform_get_time_us(void)
uint64_t platform_get_monotonic_time_ns(void)
void platform_sleep_ms(unsigned int ms)