mirror of
https://github.com/GOSTSec/sgminer
synced 2025-02-02 10:04:33 +00:00
Convert gbt_lock to a cg_lock.
This commit is contained in:
parent
b8ed231f64
commit
b5b3ca4911
15
cgminer.c
15
cgminer.c
@ -468,7 +468,7 @@ struct pool *add_pool(void)
|
|||||||
quit(1, "Failed to pthread_cond_init in add_pool");
|
quit(1, "Failed to pthread_cond_init in add_pool");
|
||||||
cglock_init(&pool->data_lock);
|
cglock_init(&pool->data_lock);
|
||||||
mutex_init(&pool->stratum_lock);
|
mutex_init(&pool->stratum_lock);
|
||||||
mutex_init(&pool->gbt_lock);
|
cglock_init(&pool->gbt_lock);
|
||||||
INIT_LIST_HEAD(&pool->curlring);
|
INIT_LIST_HEAD(&pool->curlring);
|
||||||
|
|
||||||
/* Make sure the pool doesn't think we've been idle since time 0 */
|
/* Make sure the pool doesn't think we've been idle since time 0 */
|
||||||
@ -1612,8 +1612,9 @@ static void gen_gbt_work(struct pool *pool, struct work *work)
|
|||||||
if (now.tv_sec - pool->tv_lastwork.tv_sec > 60)
|
if (now.tv_sec - pool->tv_lastwork.tv_sec > 60)
|
||||||
update_gbt(pool);
|
update_gbt(pool);
|
||||||
|
|
||||||
mutex_lock(&pool->gbt_lock);
|
cg_ilock(&pool->gbt_lock);
|
||||||
__build_gbt_coinbase(pool);
|
__build_gbt_coinbase(pool);
|
||||||
|
cg_dlock(&pool->gbt_lock);
|
||||||
merkleroot = __gbt_merkleroot(pool);
|
merkleroot = __gbt_merkleroot(pool);
|
||||||
|
|
||||||
memcpy(work->data, &pool->gbt_version, 4);
|
memcpy(work->data, &pool->gbt_version, 4);
|
||||||
@ -1630,7 +1631,7 @@ static void gen_gbt_work(struct pool *pool, struct work *work)
|
|||||||
|
|
||||||
if (pool->gbt_workid)
|
if (pool->gbt_workid)
|
||||||
work->job_id = strdup(pool->gbt_workid);
|
work->job_id = strdup(pool->gbt_workid);
|
||||||
mutex_unlock(&pool->gbt_lock);
|
cg_runlock(&pool->gbt_lock);
|
||||||
|
|
||||||
memcpy(work->data + 4 + 32, merkleroot, 32);
|
memcpy(work->data + 4 + 32, merkleroot, 32);
|
||||||
flip32(work->data + 4 + 32, merkleroot);
|
flip32(work->data + 4 + 32, merkleroot);
|
||||||
@ -1702,7 +1703,7 @@ static bool gbt_decode(struct pool *pool, json_t *res_val)
|
|||||||
if (workid)
|
if (workid)
|
||||||
applog(LOG_DEBUG, "workid: %s", workid);
|
applog(LOG_DEBUG, "workid: %s", workid);
|
||||||
|
|
||||||
mutex_lock(&pool->gbt_lock);
|
cg_wlock(&pool->gbt_lock);
|
||||||
free(pool->coinbasetxn);
|
free(pool->coinbasetxn);
|
||||||
pool->coinbasetxn = strdup(coinbasetxn);
|
pool->coinbasetxn = strdup(coinbasetxn);
|
||||||
free(pool->longpollid);
|
free(pool->longpollid);
|
||||||
@ -1727,7 +1728,7 @@ static bool gbt_decode(struct pool *pool, json_t *res_val)
|
|||||||
hex2bin((unsigned char *)&pool->gbt_bits, bits, 4);
|
hex2bin((unsigned char *)&pool->gbt_bits, bits, 4);
|
||||||
|
|
||||||
__build_gbt_txns(pool, res_val);
|
__build_gbt_txns(pool, res_val);
|
||||||
mutex_unlock(&pool->gbt_lock);
|
cg_wunlock(&pool->gbt_lock);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -6011,11 +6012,11 @@ retry_pool:
|
|||||||
/* Update the longpollid every time, but do it under lock to
|
/* Update the longpollid every time, but do it under lock to
|
||||||
* avoid races */
|
* avoid races */
|
||||||
if (pool->has_gbt) {
|
if (pool->has_gbt) {
|
||||||
mutex_lock(&pool->gbt_lock);
|
cg_rlock(&pool->gbt_lock);
|
||||||
sprintf(lpreq, "{\"id\": 0, \"method\": \"getblocktemplate\", \"params\": "
|
sprintf(lpreq, "{\"id\": 0, \"method\": \"getblocktemplate\", \"params\": "
|
||||||
"[{\"capabilities\": [\"coinbasetxn\", \"workid\", \"coinbase/append\"], "
|
"[{\"capabilities\": [\"coinbasetxn\", \"workid\", \"coinbase/append\"], "
|
||||||
"\"longpollid\": \"%s\"}]}\n", pool->longpollid);
|
"\"longpollid\": \"%s\"}]}\n", pool->longpollid);
|
||||||
mutex_unlock(&pool->gbt_lock);
|
cg_runlock(&pool->gbt_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Longpoll connections can be persistent for a very long time
|
/* Longpoll connections can be persistent for a very long time
|
||||||
|
2
miner.h
2
miner.h
@ -1066,7 +1066,7 @@ struct pool {
|
|||||||
|
|
||||||
/* GBT variables */
|
/* GBT variables */
|
||||||
bool has_gbt;
|
bool has_gbt;
|
||||||
pthread_mutex_t gbt_lock;
|
cglock_t gbt_lock;
|
||||||
unsigned char previousblockhash[32];
|
unsigned char previousblockhash[32];
|
||||||
unsigned char gbt_target[32];
|
unsigned char gbt_target[32];
|
||||||
char *coinbasetxn;
|
char *coinbasetxn;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user