refactor: move times API to utils.h
This commit is contained in:
@@ -7,6 +7,31 @@ extern "C"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
/*
|
||||
* The maximum number of seconds that can be stored in the time_t value is 2147483647 –- a little over 68 years.
|
||||
*
|
||||
* struct timespec
|
||||
* {
|
||||
* time_t tv_sec; // seconds
|
||||
* long tv_nsec; // nanoseconds
|
||||
* };
|
||||
*
|
||||
* 1 s = 1000 ms
|
||||
* 1 ms = 1000 us
|
||||
* 1 us = 1000 ns
|
||||
*/
|
||||
|
||||
#define TIMESPEC_TO_MSEC(ts) ((ts).tv_sec * 1000 + (ts).tv_nsec / 1000000)
|
||||
|
||||
static inline uint64_t clock_get_real_time_ms()
|
||||
{
|
||||
struct timespec now;
|
||||
clock_gettime(CLOCK_REALTIME_COARSE, &now);
|
||||
|
||||
return TIMESPEC_TO_MSEC(now);
|
||||
}
|
||||
|
||||
static inline void hexdump_to_fd(int fd, uint32_t idx, const char *data, uint16_t len)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user