Provide a timeval_to_cgtime helper function to reuse values.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
diff --git a/util.c b/util.c
index 95419c5..6e82ab7 100644
--- a/util.c
+++ b/util.c
@@ -812,6 +812,11 @@ void cgtime(struct timeval *tv)
{
gettimeofday(tv, NULL);
}
+
+void timeval_to_cgtimer(cgtimer_t *cgt, const struct timeval *tv)
+{
+ timeval_to_spec(cgt, tv);
+}
#else
static void dtime_to_timeval(struct timeval *tv, DWORD dtime)
{
@@ -830,6 +835,16 @@ void cgtime(struct timeval *tv)
//timeEndPeriod(1);
dtime_to_timeval(tv, dtime);
}
+
+static void timeval_to_dtime(DWORD *dtime, const struct timeval *tv)
+{
+ *dtime = tv->tv_sec * 1000 + tv->tv_usec / 1000;
+}
+
+void timeval_to_cgtimer(cgtimer_t *cgt, const struct timeval *tv)
+{
+ timeval_to_dtime(cgt, tv);
+}
#endif
void subtime(struct timeval *a, struct timeval *b)
diff --git a/util.h b/util.h
index ed1f57f..35a267e 100644
--- a/util.h
+++ b/util.h
@@ -75,6 +75,7 @@ void thr_info_cancel(struct thr_info *thr);
void nmsleep(unsigned int msecs);
void nusleep(unsigned int usecs);
void cgtime(struct timeval *tv);
+void timeval_to_cgtimer(cgtimer_t *cgt, const struct timeval *tv);
void subtime(struct timeval *a, struct timeval *b);
void addtime(struct timeval *a, struct timeval *b);
bool time_more(struct timeval *a, struct timeval *b);