Use the reentrant cgsleep function to time sleeps on reading from avalon.
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/driver-avalon.c b/driver-avalon.c
index 91fa93a..a68ad92 100644
--- a/driver-avalon.c
+++ b/driver-avalon.c
@@ -860,20 +860,19 @@ static void *avalon_get_results(void *userdata)
{
struct cgpu_info *avalon = (struct cgpu_info *)userdata;
struct avalon_info *info = avalon->device_data;
- int offset = 0, read_delay = 0, ret = 0;
const int rsize = AVALON_FTDI_READSIZE;
char readbuf[AVALON_READBUF_SIZE];
struct thr_info *thr = info->thr;
- struct timeval tv_start, tv_end;
+ struct timespec ts_start;
+ int offset = 0, ret = 0;
char threadname[24];
snprintf(threadname, 24, "ava_recv/%d", avalon->device_id);
RenameThread(threadname);
+ cgsleep_prepare_r(&ts_start);
while (likely(!avalon->shutdown)) {
unsigned char buf[rsize];
- struct timeval tv_diff;
- int us_diff;
if (offset >= (int)AVALON_READ_SIZE)
avalon_parse_results(avalon, info, thr, readbuf, &offset);
@@ -894,17 +893,10 @@ static void *avalon_get_results(void *userdata)
* to leave the interface idle for writes to occur, but do not
* sleep if we have been receiving data, and we do not yet have
* a full result as more may be coming. */
- if (ret < 1 || offset == 0) {
- cgtime(&tv_end);
- timersub(&tv_end, &tv_start, &tv_diff);
- /* Assume it has not been > 1 second so ignore tv_sec */
- us_diff = tv_diff.tv_usec;
- read_delay = AVALON_READ_TIMEOUT * 1000 - us_diff;
- if (likely(read_delay >= 1000))
- nusleep(read_delay);
- }
+ if (ret < 1 || offset == 0)
+ cgsleep_ms_r(&ts_start, AVALON_READ_TIMEOUT);
- cgtime(&tv_start);
+ cgsleep_prepare_r(&ts_start);
ret = avalon_read(avalon, buf, rsize, AVALON_READ_TIMEOUT,
C_AVALON_READ);