TimeBeginPeriod and TimeEndPeriod do not add significant overhead when run the entire time for cgminer so avoid trying to maintain balanced numbers of them for specific time calls to simplify 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
diff --git a/cgminer.c b/cgminer.c
index 8e921be..c657c97 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -37,6 +37,8 @@
#ifndef WIN32
#include <sys/resource.h>
+#else
+#include <windows.h>
#endif
#include <ccan/opt/opt.h>
#include <jansson.h>
@@ -6790,6 +6792,9 @@ static void clean_up(void)
#endif
cgtime(&total_tv_end);
+#ifdef WIN32
+ timeEndPeriod(1);
+#endif
#ifdef HAVE_CURSES
disable_curses();
#endif
@@ -7449,6 +7454,8 @@ int main(int argc, char *argv[])
sigaction(SIGINT, &handler, &inthandler);
#ifndef WIN32
signal(SIGPIPE, SIG_IGN);
+#else
+ timeBeginPeriod(1);
#endif
opt_kernel_path = alloca(PATH_MAX);
strcpy(opt_kernel_path, CGMINER_PREFIX);
diff --git a/util.c b/util.c
index f555c6e..f0b39c9 100644
--- a/util.c
+++ b/util.c
@@ -807,24 +807,10 @@ void thr_info_cancel(struct thr_info *thr)
/* 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. */
-#ifndef WIN32
void cgtime(struct timeval *tv)
{
gettimeofday(tv, NULL);
}
-#else
-static void __cgtime(struct timeval *tv)
-{
- gettimeofday(tv, NULL);
-}
-
-void cgtime(struct timeval *tv)
-{
- timeBeginPeriod(1);
- __cgtime(tv);
- timeEndPeriod(1);
-}
-#endif
void subtime(struct timeval *a, struct timeval *b)
{
@@ -938,8 +924,7 @@ void cgsleep_us_r(cgtimer_t *ts_start, int64_t us)
#else
void cgsleep_prepare_r(cgtimer_t *ts_start)
{
- timeBeginPeriod(1);
- __cgtime(ts_start);
+ cgtime(ts_start);
}
static void ms_to_timeval(struct timeval *val, int ms)
@@ -957,14 +942,12 @@ void cgsleep_ms_r(cgtimer_t *ts_start, int ms)
ms_to_timeval(&tv_diff, ms);
timeradd(ts_start, &tv_diff, &tv_end);
- __cgtime(&now);
+ cgtime(&now);
if (unlikely(time_more(&now, &tv_end)))
- goto out;
+ return;
timersub(&tv_end, &now, &tv_diff);
timeval_to_spec(&ts_diff, &tv_diff);
nanosleep(&ts_diff, NULL);
-out:
- timeEndPeriod(1);
}
void cgsleep_us_r(cgtimer_t *ts_start, int64_t us)