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
2019-03-24 03:25:29 +01:00

32 lines
703 B
C

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