Convert the control_lock to a cg_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
diff --git a/api.c b/api.c
index 96c087a..93dc51b 100644
--- a/api.c
+++ b/api.c
@@ -2449,16 +2449,16 @@ static void switchpool(struct io_data *io_data, __maybe_unused SOCKETTYPE c, cha
}
id = atoi(param);
- mutex_lock(&control_lock);
+ cg_rlock(&control_lock);
if (id < 0 || id >= total_pools) {
- mutex_unlock(&control_lock);
+ cg_runlock(&control_lock);
message(io_data, MSG_INVPID, id, NULL, isjson);
return;
}
pool = pools[id];
pool->enabled = POOL_ENABLED;
- mutex_unlock(&control_lock);
+ cg_runlock(&control_lock);
switch_pools(pool);
message(io_data, MSG_SWITCHP, id, NULL, isjson);
diff --git a/cgminer.c b/cgminer.c
index 6e7cb95..b47618a 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -195,7 +195,7 @@ pthread_cond_t gws_cond;
double total_mhashes_done;
static struct timeval total_tv_start, total_tv_end;
-pthread_mutex_t control_lock;
+cglock_t control_lock;
pthread_mutex_t stats_lock;
int hw_errors;
@@ -503,9 +503,9 @@ struct pool *current_pool(void)
{
struct pool *pool;
- mutex_lock(&control_lock);
+ cg_rlock(&control_lock);
pool = currentpool;
- mutex_unlock(&control_lock);
+ cg_runlock(&control_lock);
return pool;
}
@@ -1423,9 +1423,9 @@ static struct work *make_work(void)
if (unlikely(!work))
quit(1, "Failed to calloc work in make_work");
- mutex_lock(&control_lock);
+ cg_wlock(&control_lock);
work->id = total_work++;
- mutex_unlock(&control_lock);
+ cg_wunlock(&control_lock);
return work;
}
@@ -2411,14 +2411,14 @@ static uint64_t share_diff(const struct work *work)
if (unlikely(!d64))
d64 = 1;
ret = diffone / d64;
- mutex_lock(&control_lock);
+ cg_wlock(&control_lock);
if (ret > best_diff) {
best_diff = ret;
suffix_string(best_diff, best_share, 0);
}
if (ret > work->pool->best_diff)
work->pool->best_diff = ret;
- mutex_unlock(&control_lock);
+ cg_wunlock(&control_lock);
return ret;
}
@@ -3390,7 +3390,7 @@ void switch_pools(struct pool *selected)
struct pool *pool, *last_pool;
int i, pool_no, next_pool;
- mutex_lock(&control_lock);
+ cg_wlock(&control_lock);
last_pool = currentpool;
pool_no = currentpool->pool_no;
@@ -3445,7 +3445,7 @@ void switch_pools(struct pool *selected)
currentpool = pools[pool_no];
pool = currentpool;
- mutex_unlock(&control_lock);
+ cg_wunlock(&control_lock);
/* Set the lagging flag to avoid pool not providing work fast enough
* messages in failover only mode since we have to get all fresh work
@@ -4816,9 +4816,9 @@ static int cp_prio(void)
{
int prio;
- mutex_lock(&control_lock);
+ cg_rlock(&control_lock);
prio = currentpool->prio;
- mutex_unlock(&control_lock);
+ cg_runlock(&control_lock);
return prio;
}
@@ -6977,14 +6977,14 @@ static void *test_pool_thread(void *arg)
pool_tset(pool, &pool->lagging);
pool_tclear(pool, &pool->idle);
- mutex_lock(&control_lock);
+ cg_wlock(&control_lock);
if (!pools_active) {
currentpool = pool;
if (pool->pool_no != 0)
applog(LOG_NOTICE, "Switching to pool %d %s - first alive pool", pool->pool_no, pool->rpc_url);
pools_active = true;
}
- mutex_unlock(&control_lock);
+ cg_wunlock(&control_lock);
pool_resus(pool);
} else
pool_died(pool);
@@ -7035,7 +7035,7 @@ int main(int argc, char *argv[])
mutex_init(&hash_lock);
mutex_init(&console_lock);
- mutex_init(&control_lock);
+ cglock_init(&control_lock);
mutex_init(&stats_lock);
mutex_init(&sharelog_lock);
mutex_init(&ch_lock);
diff --git a/miner.h b/miner.h
index fadbf09..7d06c85 100644
--- a/miner.h
+++ b/miner.h
@@ -793,7 +793,7 @@ extern int opt_expiry;
extern pthread_mutex_t cgusb_lock;
#endif
-extern pthread_mutex_t control_lock;
+extern cglock_t control_lock;
extern pthread_mutex_t hash_lock;
extern pthread_mutex_t console_lock;
extern pthread_mutex_t ch_lock;