Move two more timer functions out of define macros to enable them to be used by future osx code.
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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
diff --git a/util.c b/util.c
index cf28a08..8b27255 100644
--- a/util.c
+++ b/util.c
@@ -891,9 +891,40 @@ void cgtimer_sub(cgtimer_t *a, cgtimer_t *b, cgtimer_t *res)
}
}
+/* Subtract b from a */
+static void __maybe_unused timersubspec(struct timespec *a, const struct timespec *b)
+{
+ a->tv_sec -= b->tv_sec;
+ a->tv_nsec -= b->tv_nsec;
+ if (a->tv_nsec < 0) {
+ a->tv_nsec += 1000000000;
+ a->tv_sec--;
+ }
+}
+
+static void __maybe_unused cgsleep_spec(struct timespec *ts_diff, const struct timespec *ts_start)
+{
+ struct timespec now;
+
+ timeraddspec(ts_diff, ts_start);
+ cgtimer_time(&now);
+ timersubspec(ts_diff, &now);
+ if (unlikely(ts_diff->tv_sec < 0))
+ return;
+ nanosleep(ts_diff, NULL);
+}
+
/* These are cgminer specific sleep functions that use an absolute nanosecond
* resolution timer to avoid poor usleep accuracy and overruns. */
#ifndef WIN32
+/* This is a cgminer gettimeofday wrapper. Since we always call gettimeofday
+ * with tz set to NULL, and windows' default resolution is only 15ms, this
+ * gives us higher resolution times on windows. */
+void cgtime(struct timeval *tv)
+{
+ gettimeofday(tv, NULL);
+}
+
void cgtimer_time(cgtimer_t *ts_start)
{
clock_gettime(CLOCK_MONOTONIC, ts_start);
@@ -933,14 +964,6 @@ int cgtimer_to_ms(cgtimer_t *cgt)
{
return timespec_to_ms(cgt);
}
-
-/* This is a cgminer gettimeofday wrapper. Since we always call gettimeofday
- * with tz set to NULL, and windows' default resolution is only 15ms, this
- * gives us higher resolution times on windows. */
-void cgtime(struct timeval *tv)
-{
- gettimeofday(tv, NULL);
-}
#else
/* Windows start time is since 1601 lol so convert it to unix epoch 1970. */
#define EPOCHFILETIME (116444736000000000LL)
@@ -978,29 +1001,6 @@ void cgtimer_time(cgtimer_t *ts_start)
ts_start->tv_nsec = lidiv.quot * 100;
}
-/* Subtract b from a */
-static void timersubspec(struct timespec *a, const struct timespec *b)
-{
- a->tv_sec -= b->tv_sec;
- a->tv_nsec -= b->tv_nsec;
- if (a->tv_nsec < 0) {
- a->tv_nsec += 1000000000;
- a->tv_sec--;
- }
-}
-
-static void cgsleep_spec(struct timespec *ts_diff, const struct timespec *ts_start)
-{
- struct timespec now;
-
- timeraddspec(ts_diff, ts_start);
- cgtimer_time(&now);
- timersubspec(ts_diff, &now);
- if (unlikely(ts_diff->tv_sec < 0))
- return;
- nanosleep(ts_diff, NULL);
-}
-
void cgsleep_ms_r(cgtimer_t *ts_start, int ms)
{
struct timespec ts_diff;