Abstract out ms to timeval as a function.
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
diff --git a/driver-bitforce.c b/driver-bitforce.c
index 7d51ce3..83f0582 100644
--- a/driver-bitforce.c
+++ b/driver-bitforce.c
@@ -378,6 +378,12 @@ static void biforce_thread_enable(struct thr_info *thr)
bitforce_init(bitforce);
}
+static void ms_to_timeval(unsigned int mstime, struct timeval *ttime)
+{
+ ttime->tv_sec = mstime / 1000;
+ ttime->tv_usec = mstime * 1000 - (ttime->tv_sec * 1000000);
+}
+
static uint64_t bitforce_scanhash(struct thr_info *thr, struct work *work, uint64_t __maybe_unused max_nonce)
{
struct cgpu_info *bitforce = thr->cgpu;
@@ -391,8 +397,7 @@ static uint64_t bitforce_scanhash(struct thr_info *thr, struct work *work, uint6
/* Initially wait 2/3 of the average cycle time so we can request more
work before full scan is up */
sleep_time = (2 * bitforce->sleep_ms) / 3;
- tdiff.tv_sec = sleep_time / 1000;
- tdiff.tv_usec = sleep_time * 1000 - (tdiff.tv_sec * 1000000);
+ ms_to_timeval(sleep_time, &tdiff);
if (!restart_wait(&tdiff))
return 1;
@@ -401,8 +406,7 @@ static uint64_t bitforce_scanhash(struct thr_info *thr, struct work *work, uint6
/* Now wait athe final 1/3rd; no bitforce should be finished by now */
sleep_time = bitforce->sleep_ms - sleep_time;
- tdiff.tv_sec = sleep_time / 1000;
- tdiff.tv_usec = sleep_time * 1000 - (tdiff.tv_sec * 1000000);
+ ms_to_timeval(sleep_time, &tdiff);
if (!restart_wait(&tdiff))
return 1;