Provide wrappers for grabbing of thr value under the 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 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 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
diff --git a/api.c b/api.c
index 1a2f312..84a947c 100644
--- a/api.c
+++ b/api.c
@@ -1800,9 +1800,7 @@ static void pgaenable(struct io_data *io_data, __maybe_unused SOCKETTYPE c, char
#endif
for (i = 0; i < mining_threads; i++) {
- mutex_lock(&mining_thr_lock);
- thr = mining_thr[i];
- mutex_unlock(&mining_thr_lock);
+ thr = get_thread(i);
pga = thr->cgpu->cgminer_id;
if (pga == dev) {
cgpu->deven = DEV_ENABLED;
@@ -2107,9 +2105,7 @@ static void gpuenable(struct io_data *io_data, __maybe_unused SOCKETTYPE c, char
}
for (i = 0; i < gpu_threads; i++) {
- mutex_lock(&mining_thr_lock);
- thr = mining_thr[i];
- mutex_unlock(&mining_thr_lock);
+ thr = get_thread(i);
gpu = thr->cgpu->device_id;
if (gpu == id) {
if (thr->cgpu->status != LIFE_WELL) {
diff --git a/cgminer.c b/cgminer.c
index cfc2cfa..f8efa62 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -365,6 +365,23 @@ static void applog_and_exit(const char *fmt, ...)
static pthread_mutex_t sharelog_lock;
static FILE *sharelog_file = NULL;
+struct thr_info *get_thread(int thr_id)
+{
+ struct thr_info *thr;
+
+ mutex_lock(&mining_thr_lock);
+ thr = mining_thr[thr_id];
+ mutex_unlock(&mining_thr_lock);
+ return thr;
+}
+
+static struct cgpu_info *get_thr_cgpu(int thr_id)
+{
+ struct thr_info *thr = get_thread(thr_id);
+
+ return thr->cgpu;
+}
+
static void sharelog(const char*disposition, const struct work*work)
{
char *target, *hash, *data;
@@ -379,9 +396,7 @@ static void sharelog(const char*disposition, const struct work*work)
return;
thr_id = work->thr_id;
- mutex_lock(&mining_thr_lock);
- cgpu = mining_thr[thr_id]->cgpu;
- mutex_unlock(&mining_thr_lock);
+ cgpu = get_thr_cgpu(thr_id);
pool = work->pool;
t = (unsigned long int)(work->tv_work_found.tv_sec);
target = bin2hex(work->target, sizeof(work->target));
@@ -1726,11 +1741,7 @@ out:
int dev_from_id(int thr_id)
{
- struct cgpu_info *cgpu;
-
- mutex_lock(&mining_thr_lock);
- cgpu = mining_thr[thr_id]->cgpu;
- mutex_unlock(&mining_thr_lock);
+ struct cgpu_info *cgpu = get_thr_cgpu(thr_id);
return cgpu->device_id;
}
@@ -1907,10 +1918,7 @@ static void text_print_status(int thr_id)
struct cgpu_info *cgpu;
char logline[256];
- mutex_lock(&mining_thr_lock);
- cgpu = mining_thr[thr_id]->cgpu;
- mutex_unlock(&mining_thr_lock);
-
+ cgpu = get_thr_cgpu(thr_id);
if (cgpu) {
get_statline(logline, cgpu);
printf("%s\n", logline);
@@ -1979,9 +1987,7 @@ static void curses_print_devstatus(int thr_id)
char displayed_hashes[16], displayed_rolling[16];
uint64_t dh64, dr64;
- mutex_lock(&mining_thr_lock);
- cgpu = mining_thr[thr_id]->cgpu;
- mutex_unlock(&mining_thr_lock);
+ cgpu = get_thr_cgpu(thr_id);
if (devcursor + cgpu->cgminer_id > LINES - 2 || opt_compact)
return;
@@ -2232,9 +2238,7 @@ share_result(json_t *val, json_t *res, json_t *err, const struct work *work,
struct pool *pool = work->pool;
struct cgpu_info *cgpu;
- mutex_lock(&mining_thr_lock);
- cgpu = mining_thr[work->thr_id]->cgpu;
- mutex_unlock(&mining_thr_lock);
+ cgpu = get_thr_cgpu(work->thr_id);
if (json_is_true(res) || (work->gbt && json_is_null(res))) {
mutex_lock(&stats_lock);
@@ -2391,9 +2395,7 @@ static bool submit_upstream_work(struct work *work, CURL *curl, bool resubmit)
char hashshow[64 + 4] = "";
char worktime[200] = "";
- mutex_lock(&mining_thr_lock);
- cgpu = mining_thr[thr_id]->cgpu;
- mutex_unlock(&mining_thr_lock);
+ cgpu = get_thr_cgpu(thr_id);
#ifdef __BIG_ENDIAN__
int swapcounter = 0;
@@ -2781,9 +2783,7 @@ static void __kill_work(void)
applog(LOG_DEBUG, "Stopping mining threads");
/* Stop the mining threads*/
for (i = 0; i < mining_threads; i++) {
- mutex_lock(&mining_thr_lock);
- thr = mining_thr[i];
- mutex_unlock(&mining_thr_lock);
+ thr = get_thread(i);
thr_info_freeze(thr);
thr->pause = true;
}
@@ -2793,9 +2793,7 @@ static void __kill_work(void)
applog(LOG_DEBUG, "Killing off mining threads");
/* Kill the mining threads*/
for (i = 0; i < mining_threads; i++) {
- mutex_lock(&mining_thr_lock);
- thr = mining_thr[i];
- mutex_unlock(&mining_thr_lock);
+ thr = get_thread(i);
thr_info_cancel(thr);
}
@@ -4443,9 +4441,7 @@ static void hashmeter(int thr_id, struct timeval *diff,
local_mhashes = (double)hashes_done / 1000000.0;
/* Update the last time this thread reported in */
if (thr_id >= 0) {
- mutex_lock(&mining_thr_lock);
- thr = mining_thr[thr_id];
- mutex_unlock(&mining_thr_lock);
+ thr = get_thread(thr_id);
gettimeofday(&(thr->last), NULL);
thr->cgpu->device_last_well = time(NULL);
}
@@ -5907,9 +5903,7 @@ static void *watchdog_thread(void __maybe_unused *userdata)
for (i = 0; i < mining_threads; i++) {
struct thr_info *thr;
- mutex_lock(&mining_thr_lock);
- thr = mining_thr[i];
- mutex_unlock(&mining_thr_lock);
+ thr = get_thread(i);
/* Don't touch disabled devices */
if (thr->cgpu->deven == DEV_DISABLED)
@@ -6855,9 +6849,7 @@ begin_bench:
cgpu->status = LIFE_INIT;
for (j = 0; j < cgpu->threads; ++j, ++k) {
- mutex_lock(&mining_thr_lock);
- thr = mining_thr[k];
- mutex_unlock(&mining_thr_lock);
+ thr = get_thread(k);
thr->id = k;
thr->cgpu = cgpu;
thr->device_thread = j;
diff --git a/driver-opencl.c b/driver-opencl.c
index 0521ac1..9e9e401 100644
--- a/driver-opencl.c
+++ b/driver-opencl.c
@@ -618,10 +618,7 @@ void pause_dynamic_threads(int gpu)
for (i = 1; i < cgpu->threads; i++) {
struct thr_info *thr;
- mutex_lock(&mining_thr_lock);
- thr = mining_thr[i];
- mutex_unlock(&mining_thr_lock);
-
+ thr = get_thread(i);
if (!thr->pause && cgpu->dynamic) {
applog(LOG_WARNING, "Disabling extra threads due to dynamic mode.");
applog(LOG_WARNING, "Tune dynamic intensity with --gpu-dyninterval");
@@ -709,9 +706,7 @@ retry:
else
wlog("%d\n", gpus[gpu].intensity);
for (i = 0; i < mining_threads; i++) {
- mutex_lock(&mining_thr_lock);
- thr = mining_thr[i];
- mutex_unlock(&mining_thr_lock);
+ thr = get_thread(i);
if (thr->cgpu != cgpu)
continue;
get_datestamp(checkin, &thr->last);
@@ -766,9 +761,7 @@ retry:
}
gpus[selected].deven = DEV_ENABLED;
for (i = 0; i < mining_threads; ++i) {
- mutex_lock(&mining_thr_lock);
- thr = mining_thr[i];
- mutex_unlock(&mining_thr_lock);
+ thr = get_thread(i);
cgpu = thr->cgpu;
if (cgpu->drv->drv_id != DRIVER_OPENCL)
continue;
@@ -1155,18 +1148,14 @@ select_cgpu:
gpu = cgpu->device_id;
for (thr_id = 0; thr_id < mining_threads; ++thr_id) {
- mutex_lock(&mining_thr_lock);
- thr = mining_thr[thr_id];
- mutex_unlock(&mining_thr_lock);
+ thr = get_thread(thr_id);
cgpu = thr->cgpu;
if (cgpu->drv->drv_id != DRIVER_OPENCL)
continue;
if (dev_from_id(thr_id) != gpu)
continue;
- mutex_lock(&mining_thr_lock);
- thr = mining_thr[thr_id];
- mutex_unlock(&mining_thr_lock);
+ thr = get_thread(thr_id);
if (!thr) {
applog(LOG_WARNING, "No reference to thread %d exists", thr_id);
continue;
@@ -1184,9 +1173,7 @@ select_cgpu:
for (thr_id = 0; thr_id < mining_threads; ++thr_id) {
int virtual_gpu;
- mutex_lock(&mining_thr_lock);
- thr = mining_thr[thr_id];
- mutex_unlock(&mining_thr_lock);
+ thr = get_thread(thr_id);
cgpu = thr->cgpu;
if (cgpu->drv->drv_id != DRIVER_OPENCL)
continue;
@@ -1223,9 +1210,7 @@ select_cgpu:
get_datestamp(cgpu->init, &now);
for (thr_id = 0; thr_id < mining_threads; ++thr_id) {
- mutex_lock(&mining_thr_lock);
- thr = mining_thr[thr_id];
- mutex_unlock(&mining_thr_lock);
+ thr = get_thread(thr_id);
cgpu = thr->cgpu;
if (cgpu->drv->drv_id != DRIVER_OPENCL)
continue;
diff --git a/miner.h b/miner.h
index 87d58fe..a862af6 100644
--- a/miner.h
+++ b/miner.h
@@ -1101,6 +1101,7 @@ extern void clean_work(struct work *work);
extern void free_work(struct work *work);
extern void __copy_work(struct work *work, struct work *base_work);
extern struct work *copy_work(struct work *base_work);
+extern struct thr_info *get_thread(int thr_id);
enum api_data_type {
API_ESCAPE,