Provide cgtimer_to_ms helper functions.
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 46 47 48 49
diff --git a/util.c b/util.c
index f2272ab..28ac02d 100644
--- a/util.c
+++ b/util.c
@@ -921,6 +921,15 @@ void cgsleep_us_r(cgtimer_t *ts_start, int64_t us)
nanosleep_abstime(&ts_end);
}
+static int timespec_to_ms(struct timespec *ts)
+{
+ return ts->tv_sec * 1000 + ts->tv_nsec / 1000000;
+}
+
+int cgtimer_to_ms(cgtimer_t *cgt)
+{
+ return timespec_to_ms(cgt);
+}
#else
void cgtimer_time(cgtimer_t *ts_start)
{
@@ -956,6 +965,16 @@ void cgsleep_us_r(cgtimer_t *ts_start, int64_t us)
cgsleep_ms_r(ts_start, ms);
}
+
+static int timeval_to_ms(struct timeval *tv)
+{
+ return tv->tv_sec * 1000 + tv->tv_usec / 1000;
+}
+
+int cgtimer_to_ms(cgtimer_t *cgt)
+{
+ return timeval_to_ms(cgt);
+}
#endif
void cgsleep_ms(int ms)
diff --git a/util.h b/util.h
index d864bc5..53efda6 100644
--- a/util.h
+++ b/util.h
@@ -90,6 +90,7 @@ void cgtimer_time(cgtimer_t *ts_start);
#define cgsleep_prepare_r(ts_start) cgtimer_time(ts_start)
void cgsleep_ms_r(cgtimer_t *ts_start, int ms);
void cgsleep_us_r(cgtimer_t *ts_start, int64_t us);
+int cgtimer_to_ms(cgtimer_t *cgt);
double us_tdiff(struct timeval *end, struct timeval *start);
double tdiff(struct timeval *end, struct timeval *start);
bool stratum_send(struct pool *pool, char *s, ssize_t len);