The write thread in avalon is only ever actually woken up by timeout so remove the write semaphore and use a simple sleep poll.
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 91
diff --git a/driver-avalon.c b/driver-avalon.c
index d09da5b..1849fed 100644
--- a/driver-avalon.c
+++ b/driver-avalon.c
@@ -702,11 +702,9 @@ static bool avalon_detect_one(libusb_device *dev, struct usb_find_devices *found
if (!add_cgpu(avalon))
goto unshin;
- cgsem_init(&info->write_sem);
-
ret = avalon_reset(avalon, true);
if (ret && !configured)
- goto unshinsem;
+ goto unshin;
update_usb_stats(avalon);
@@ -730,10 +728,6 @@ static bool avalon_detect_one(libusb_device *dev, struct usb_find_devices *found
return true;
-unshinsem:
-
- cgsem_destroy(&info->write_sem);
-
unshin:
usb_uninit(avalon);
@@ -976,7 +970,7 @@ static void *avalon_send_tasks(void *userdata)
bool idled = false;
while (avalon_buffer_full(avalon))
- cgsem_wait(&info->write_sem);
+ nmsleep(40);
if (opt_avalon_auto && info->auto_queued >= AVALON_AUTO_CYCLE) {
mutex_lock(&info->lock);
@@ -1014,7 +1008,7 @@ static void *avalon_send_tasks(void *userdata)
break;
else {
while (avalon_buffer_full(avalon))
- cgsem_wait(&info->write_sem);
+ nmsleep(40);
}
}
@@ -1100,8 +1094,6 @@ static void do_avalon_close(struct thr_info *thr)
avalon_running_reset(avalon, info);
info->no_matching_work = 0;
-
- cgsem_destroy(&info->write_sem);
}
static inline void record_temp_fan(struct avalon_info *info, struct avalon_result *ar, float *temp_avg)
@@ -1284,7 +1276,6 @@ static int64_t avalon_scanhash(struct thr_info *thr)
struct timeval now, then, tdiff;
int64_t hash_count, us_timeout;
struct timespec abstime;
- int ret;
/* Half nonce range */
us_timeout = 0x80000000ll / info->asic_count / info->frequency;
@@ -1298,14 +1289,9 @@ static int64_t avalon_scanhash(struct thr_info *thr)
/* Wait until avalon_send_tasks signals us that it has completed
* sending its work or a full nonce range timeout has occurred */
mutex_lock(&info->qlock);
- ret = pthread_cond_timedwait(&info->qcond, &info->qlock, &abstime);
+ pthread_cond_timedwait(&info->qcond, &info->qlock, &abstime);
mutex_unlock(&info->qlock);
- /* If we timed out, avalon_send_tasks may be stuck waiting on the
- * write_sem, so force it to check for avalon_buffer_full itself. */
- if (ret)
- cgsem_post(&info->write_sem);
-
mutex_lock(&info->lock);
hash_count = 0xffffffffull * (uint64_t)info->nonces;
avalon->results += info->nonces + info->idle;
diff --git a/driver-avalon.h b/driver-avalon.h
index b482e21..93f092d 100644
--- a/driver-avalon.h
+++ b/driver-avalon.h
@@ -132,7 +132,6 @@ struct avalon_info {
pthread_mutex_t lock;
pthread_mutex_t qlock;
pthread_cond_t qcond;
- cgsem_t write_sem;
int nonces;
int auto_queued;