1
0
mirror of https://github.com/falk-werner/webfuse synced 2024-10-27 20:34:10 +00:00
falk-werner_webfuse/lib/wsfs/adapter/impl/time/timepoint.c

32 lines
703 B
C
Raw Normal View History

#include "wsfs/adapter/impl/time/timepoint.h"
2019-02-09 18:02:53 +00:00
#include <time.h>
#define WSFS_MSEC_PER_SEC ((timepoint) 1000)
#define WSFS_NSEC_PER_MSEC ((timepoint) 1000 * 1000)
2019-02-09 18:02:53 +00:00
timepoint timepoint_now(void)
2019-02-09 18:02:53 +00:00
{
struct timespec tp;
clock_gettime(CLOCK_MONOTONIC, &tp);
2019-02-09 18:02:53 +00:00
timepoint const now = (tp.tv_sec * WSFS_MSEC_PER_SEC) + (tp.tv_nsec / WSFS_NSEC_PER_MSEC);
2019-02-09 18:02:53 +00:00
return now;
}
timepoint timepoint_in_msec(timediff value)
2019-02-09 18:02:53 +00:00
{
timepoint const now = timepoint_now();
timepoint result = now + ((timepoint) value);
2019-02-09 18:02:53 +00:00
return result;
}
bool timepoint_is_elapsed(timepoint tp)
2019-02-09 18:02:53 +00:00
{
timepoint const now = timepoint_now();
timediff const diff = (timediff) (tp - now);
2019-02-09 18:02:53 +00:00
return (0 > diff);
}