make rw locks: mining_thr_lock and devices_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 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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
diff --git a/api.c b/api.c
index f30a75e..6acf601 100644
--- a/api.c
+++ b/api.c
@@ -1161,7 +1161,7 @@ static int numpgas()
int count = 0;
int i;
- mutex_lock(&devices_lock);
+ rd_lock(&devices_lock);
for (i = 0; i < total_devices; i++) {
#ifdef USE_BITFORCE
if (devices[i]->drv->drv_id == DRIVER_BITFORCE)
@@ -1180,7 +1180,7 @@ static int numpgas()
count++;
#endif
}
- mutex_unlock(&devices_lock);
+ rd_unlock(&devices_lock);
return count;
}
@@ -1189,7 +1189,7 @@ static int pgadevice(int pgaid)
int count = 0;
int i;
- mutex_lock(&devices_lock);
+ rd_lock(&devices_lock);
for (i = 0; i < total_devices; i++) {
#ifdef USE_BITFORCE
if (devices[i]->drv->drv_id == DRIVER_BITFORCE)
@@ -1211,12 +1211,12 @@ static int pgadevice(int pgaid)
goto foundit;
}
- mutex_unlock(&devices_lock);
+ rd_unlock(&devices_lock);
return -1;
foundit:
- mutex_unlock(&devices_lock);
+ rd_unlock(&devices_lock);
return i;
}
#endif
diff --git a/cgminer.c b/cgminer.c
index 2a51afe..e488592 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -180,8 +180,8 @@ static pthread_rwlock_t blk_lock;
static pthread_mutex_t sshare_lock;
pthread_rwlock_t netacc_lock;
-pthread_mutex_t mining_thr_lock;
-pthread_mutex_t devices_lock;
+pthread_rwlock_t mining_thr_lock;
+pthread_rwlock_t devices_lock;
static pthread_mutex_t lp_lock;
static pthread_cond_t lp_cond;
@@ -379,9 +379,9 @@ struct thr_info *get_thread(int thr_id)
{
struct thr_info *thr;
- mutex_lock(&mining_thr_lock);
+ rd_lock(&mining_thr_lock);
thr = mining_thr[thr_id];
- mutex_unlock(&mining_thr_lock);
+ rd_unlock(&mining_thr_lock);
return thr;
}
@@ -396,9 +396,9 @@ struct cgpu_info *get_devices(int id)
{
struct cgpu_info *cgpu;
- mutex_lock(&devices_lock);
+ rd_lock(&devices_lock);
cgpu = devices[id];
- mutex_unlock(&devices_lock);
+ rd_unlock(&devices_lock);
return cgpu;
}
@@ -762,24 +762,24 @@ static void load_temp_cutoffs()
if (val < 0 || val > 200)
quit(1, "Invalid value passed to set temp cutoff");
- mutex_lock(&devices_lock);
+ rd_lock(&devices_lock);
devices[device]->cutofftemp = val;
- mutex_unlock(&devices_lock);
+ rd_unlock(&devices_lock);
}
} else {
- mutex_lock(&devices_lock);
+ rd_lock(&devices_lock);
for (i = device; i < total_devices; ++i) {
if (!devices[i]->cutofftemp)
devices[i]->cutofftemp = opt_cutofftemp;
}
- mutex_unlock(&devices_lock);
+ rd_unlock(&devices_lock);
return;
}
if (device <= 1) {
- mutex_lock(&devices_lock);
+ rd_lock(&devices_lock);
for (i = device; i < total_devices; ++i)
devices[i]->cutofftemp = val;
- mutex_unlock(&devices_lock);
+ rd_unlock(&devices_lock);
}
}
@@ -3496,10 +3496,10 @@ static void restart_threads(void)
/* Discard staged work that is now stale */
discard_stale();
- mutex_lock(&mining_thr_lock);
+ rd_lock(&mining_thr_lock);
for (i = 0; i < mining_threads; i++)
mining_thr[i]->work_restart = true;
- mutex_unlock(&mining_thr_lock);
+ rd_unlock(&mining_thr_lock);
mutex_lock(&restart_lock);
pthread_cond_broadcast(&restart_cond);
@@ -6152,10 +6152,10 @@ static void *watchdog_thread(void __maybe_unused *userdata)
applog(LOG_WARNING, "Will restart execution as scheduled at %02d:%02d",
schedstart.tm.tm_hour, schedstart.tm.tm_min);
sched_paused = true;
- mutex_lock(&mining_thr_lock);
+ rd_lock(&mining_thr_lock);
for (i = 0; i < mining_threads; i++)
mining_thr[i]->pause = true;
- mutex_unlock(&mining_thr_lock);
+ rd_unlock(&mining_thr_lock);
} else if (sched_paused && should_run()) {
applog(LOG_WARNING, "Restarting execution as per start time %02d:%02d scheduled",
schedstart.tm.tm_hour, schedstart.tm.tm_min);
@@ -6719,9 +6719,9 @@ void fill_device_drv(struct cgpu_info *cgpu)
void enable_device(struct cgpu_info *cgpu)
{
cgpu->deven = DEV_ENABLED;
- mutex_lock(&devices_lock);
+ wr_lock(&devices_lock);
devices[cgpu->cgminer_id = cgminer_id_count++] = cgpu;
- mutex_unlock(&devices_lock);
+ wr_unlock(&devices_lock);
if (hotplug_mode) {
new_threads += cgpu->threads;
#ifdef HAVE_CURSES
@@ -6764,9 +6764,9 @@ bool add_cgpu(struct cgpu_info*cgpu)
cgpu->device_id = d->lastid = 0;
HASH_ADD_STR(devids, name, d);
}
- mutex_lock(&devices_lock);
+ wr_lock(&devices_lock);
devices = realloc(devices, sizeof(struct cgpu_info *) * (total_devices + new_devices + 2));
- mutex_unlock(&devices_lock);
+ wr_unlock(&devices_lock);
if (hotplug_mode)
devices[total_devices + new_devices++] = cgpu;
else
@@ -6802,9 +6802,9 @@ static void hotplug_process()
cgpu->rolling = cgpu->total_mhashes = 0;
}
- mutex_lock(&mining_thr_lock);
+ wr_lock(&mining_thr_lock);
mining_thr = realloc(mining_thr, sizeof(thr) * (mining_threads + new_threads + 1));
- mutex_unlock(&mining_thr_lock);
+ wr_unlock(&mining_thr_lock);
if (!mining_thr)
quit(1, "Failed to hotplug realloc mining_thr");
for (i = 0; i < new_threads; i++) {
@@ -6933,8 +6933,8 @@ int main(int argc, char *argv[])
mutex_init(&sshare_lock);
rwlock_init(&blk_lock);
rwlock_init(&netacc_lock);
- mutex_init(&mining_thr_lock);
- mutex_init(&devices_lock);
+ rwlock_init(&mining_thr_lock);
+ rwlock_init(&devices_lock);
mutex_init(&lp_lock);
if (unlikely(pthread_cond_init(&lp_cond, NULL)))
diff --git a/miner.h b/miner.h
index 07918c6..5520d87 100644
--- a/miner.h
+++ b/miner.h
@@ -757,8 +757,8 @@ extern pthread_mutex_t cgusb_lock;
extern pthread_mutex_t hash_lock;
extern pthread_mutex_t console_lock;
extern pthread_mutex_t ch_lock;
-extern pthread_mutex_t mining_thr_lock;
-extern pthread_mutex_t devices_lock;
+extern pthread_rwlock_t mining_thr_lock;
+extern pthread_rwlock_t devices_lock;
extern pthread_mutex_t restart_lock;
extern pthread_cond_t restart_cond;