Do all hotplug_process under the write mining_thr_lock
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
diff --git a/cgminer.c b/cgminer.c
index 6e708fe..b5199ff 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -435,12 +435,17 @@ static void applog_and_exit(const char *fmt, ...)
static pthread_mutex_t sharelog_lock;
static FILE *sharelog_file = NULL;
+static struct thr_info *__get_thread(int thr_id)
+{
+ return mining_thr[thr_id];
+}
+
struct thr_info *get_thread(int thr_id)
{
struct thr_info *thr;
rd_lock(&mining_thr_lock);
- thr = mining_thr[thr_id];
+ thr = __get_thread(thr_id);
rd_unlock(&mining_thr_lock);
return thr;
@@ -7848,7 +7853,7 @@ struct device_drv *copy_drv(struct device_drv *drv)
}
#ifdef USE_USBUTILS
-static void hotplug_process()
+static void hotplug_process(void)
{
struct thr_info *thr;
int i, j;
@@ -7866,7 +7871,6 @@ static void hotplug_process()
wr_lock(&mining_thr_lock);
mining_thr = realloc(mining_thr, sizeof(thr) * (mining_threads + new_threads + 1));
- wr_unlock(&mining_thr_lock);
if (!mining_thr)
quit(1, "Failed to hotplug realloc mining_thr");
@@ -7885,7 +7889,7 @@ static void hotplug_process()
cgtime(&(cgpu->dev_start_tv));
for (j = 0; j < cgpu->threads; ++j) {
- thr = get_thread(mining_threads);
+ thr = __get_thread(mining_threads);
thr->id = mining_threads;
thr->cgpu = cgpu;
thr->device_thread = j;
@@ -7910,6 +7914,7 @@ static void hotplug_process()
total_devices++;
applog(LOG_WARNING, "Hotplug: %s added %s %i", cgpu->drv->dname, cgpu->drv->name, cgpu->device_id);
}
+ wr_unlock(&mining_thr_lock);
adjust_mostdevs();
switch_logsize(true);