Browse Source

Use a counting semaphore to signal the usb resource thread that it has work to do.

nfactor-troky
Con Kolivas 11 years ago
parent
commit
cc04d3abc7
  1. 7
      cgminer.c
  2. 5
      miner.h
  3. 23
      usbutils.c

7
cgminer.c

@ -28,6 +28,10 @@ @@ -28,6 +28,10 @@
#include <assert.h>
#include <signal.h>
#ifdef USE_USBUTILS
#include <semaphore.h>
#endif
#include <sys/stat.h>
#include <sys/types.h>
@ -144,6 +148,7 @@ char *opt_avalon_options = NULL; @@ -144,6 +148,7 @@ char *opt_avalon_options = NULL;
char *opt_usb_select = NULL;
int opt_usbdump = -1;
bool opt_usb_list_all;
sem_t usb_resource_sem;
#endif
char *opt_kernel_path;
@ -7358,6 +7363,8 @@ int main(int argc, char *argv[]) @@ -7358,6 +7363,8 @@ int main(int argc, char *argv[])
// before device detection
if (!opt_scrypt) {
if (!sem_init(&usb_resource_sem, 0, 0))
quit(1, "Failed to sem_init usb_resource_sem");
usbres_thr_id = 1;
thr = &control_thr[usbres_thr_id];
if (thr_info_create(thr, NULL, usb_resource_thread, thr))

5
miner.h

@ -19,6 +19,10 @@ @@ -19,6 +19,10 @@
# include <netdb.h>
#endif
#ifdef USE_USBUTILS
#include <semaphore.h>
#endif
#ifdef HAVE_OPENCL
#ifdef __APPLE_CC__
#include <OpenCL/opencl.h>
@ -846,6 +850,7 @@ extern char *opt_avalon_options; @@ -846,6 +850,7 @@ extern char *opt_avalon_options;
extern char *opt_usb_select;
extern int opt_usbdump;
extern bool opt_usb_list_all;
extern sem_t usb_resource_sem;
#endif
#ifdef USE_BITFORCE
extern bool opt_bfl_noncerange;

23
usbutils.c

@ -1199,18 +1199,17 @@ static bool cgminer_usb_lock_bd(struct device_drv *drv, uint8_t bus_number, uint @@ -1199,18 +1199,17 @@ static bool cgminer_usb_lock_bd(struct device_drv *drv, uint8_t bus_number, uint
res_work->device_address = device_address;
mutex_lock(&cgusbres_lock);
res_work->next = res_work_head;
res_work_head = res_work;
mutex_unlock(&cgusbres_lock);
nmsleep(46);
sem_post(&usb_resource_sem);
// TODO: add a timeout fail - restart the resource thread?
while (true) {
mutex_lock(&cgusbres_lock);
nmsleep(50);
mutex_lock(&cgusbres_lock);
if (res_reply_head) {
struct resource_reply *res_reply_prev = NULL;
struct resource_reply *res_reply = res_reply_head;
@ -1235,10 +1234,7 @@ static bool cgminer_usb_lock_bd(struct device_drv *drv, uint8_t bus_number, uint @@ -1235,10 +1234,7 @@ static bool cgminer_usb_lock_bd(struct device_drv *drv, uint8_t bus_number, uint
res_reply = res_reply->next;
}
}
mutex_unlock(&cgusbres_lock);
nmsleep(45);
}
}
@ -1262,12 +1258,12 @@ static void cgminer_usb_unlock_bd(struct device_drv *drv, uint8_t bus_number, ui @@ -1262,12 +1258,12 @@ static void cgminer_usb_unlock_bd(struct device_drv *drv, uint8_t bus_number, ui
res_work->device_address = device_address;
mutex_lock(&cgusbres_lock);
res_work->next = res_work_head;
res_work_head = res_work;
mutex_unlock(&cgusbres_lock);
sem_post(&usb_resource_sem);
return;
}
@ -2893,15 +2889,14 @@ void *usb_resource_thread(void __maybe_unused *userdata) @@ -2893,15 +2889,14 @@ void *usb_resource_thread(void __maybe_unused *userdata)
applog(LOG_DEBUG, "RES: thread starting");
while (0*1337+1) {
mutex_lock(&cgusbres_lock);
while (42) {
/* Wait to be told we have work to do */
sem_wait(&usb_resource_sem);
mutex_lock(&cgusbres_lock);
while (res_work_head)
resource_process();
mutex_unlock(&cgusbres_lock);
nmsleep(45);
}
return NULL;

Loading…
Cancel
Save