diff --git a/cgminer.c b/cgminer.c index 64cf779d..9547fa87 100644 --- a/cgminer.c +++ b/cgminer.c @@ -5653,34 +5653,22 @@ static void hash_sole_work(struct thr_info *mythr) do { cgtime(&tv_start); - timersub(&tv_start, &getwork_start, &getwork_start); - - timeradd(&getwork_start, - &(dev_stats->getwork_wait), - &(dev_stats->getwork_wait)); - if (timercmp(&getwork_start, &(dev_stats->getwork_wait_max), >)) { - dev_stats->getwork_wait_max.tv_sec = getwork_start.tv_sec; - dev_stats->getwork_wait_max.tv_usec = getwork_start.tv_usec; - } - if (timercmp(&getwork_start, &(dev_stats->getwork_wait_min), <)) { - dev_stats->getwork_wait_min.tv_sec = getwork_start.tv_sec; - dev_stats->getwork_wait_min.tv_usec = getwork_start.tv_usec; - } + subtime(&tv_start, &getwork_start); + + addtime(&getwork_start, &dev_stats->getwork_wait); + if (time_more(&getwork_start, &dev_stats->getwork_wait_max)) + copy_time(&dev_stats->getwork_wait_max, &getwork_start); + if (time_less(&getwork_start, &dev_stats->getwork_wait_min)) + copy_time(&dev_stats->getwork_wait_min, &getwork_start); dev_stats->getwork_calls++; pool_stats = &(work->pool->cgminer_stats); - timeradd(&getwork_start, - &(pool_stats->getwork_wait), - &(pool_stats->getwork_wait)); - if (timercmp(&getwork_start, &(pool_stats->getwork_wait_max), >)) { - pool_stats->getwork_wait_max.tv_sec = getwork_start.tv_sec; - pool_stats->getwork_wait_max.tv_usec = getwork_start.tv_usec; - } - if (timercmp(&getwork_start, &(pool_stats->getwork_wait_min), <)) { - pool_stats->getwork_wait_min.tv_sec = getwork_start.tv_sec; - pool_stats->getwork_wait_min.tv_usec = getwork_start.tv_usec; - } + addtime(&getwork_start, &pool_stats->getwork_wait); + if (time_more(&getwork_start, &pool_stats->getwork_wait_max)) + copy_time(&pool_stats->getwork_wait_max, &getwork_start); + if (time_less(&getwork_start, &pool_stats->getwork_wait_min)) + copy_time(&pool_stats->getwork_wait_min, &getwork_start); pool_stats->getwork_calls++; cgtime(&(work->tv_work_start)); diff --git a/util.c b/util.c index c3693c79..c8105606 100644 --- a/util.c +++ b/util.c @@ -852,6 +852,31 @@ void cgtime(struct timeval *tv) #endif } +void subtime(struct timeval *a, struct timeval *b) +{ + timersub(a, b, b); +} + +void addtime(struct timeval *a, struct timeval *b) +{ + timeradd(a, b, b); +} + +bool time_more(struct timeval *a, struct timeval *b) +{ + return timercmp(a, b, >); +} + +bool time_less(struct timeval *a, struct timeval *b) +{ + return timercmp(a, b, <); +} + +void copy_time(struct timeval *dest, const struct timeval *src) +{ + memcpy(dest, src, sizeof(struct timeval)); +} + /* Returns the microseconds difference between end and start times as a double */ double us_tdiff(struct timeval *end, struct timeval *start) { diff --git a/util.h b/util.h index ccfa37d5..1c0187e4 100644 --- a/util.h +++ b/util.h @@ -51,6 +51,11 @@ void thr_info_freeze(struct thr_info *thr); void thr_info_cancel(struct thr_info *thr); void nmsleep(unsigned int msecs); void cgtime(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); +bool time_less(struct timeval *a, struct timeval *b); +void copy_time(struct timeval *dest, const struct timeval *src); 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);