Browse Source

Move the stratum and GBT data to be protected under a new cg_lock data_lock.

nfactor-troky
Con Kolivas 12 years ago
parent
commit
26ddd1fd20
  1. 17
      cgminer.c
  2. 1
      miner.h
  3. 16
      util.c

17
cgminer.c

@ -466,6 +466,7 @@ struct pool *add_pool(void)
mutex_init(&pool->pool_lock); mutex_init(&pool->pool_lock);
if (unlikely(pthread_cond_init(&pool->cr_cond, NULL))) if (unlikely(pthread_cond_init(&pool->cr_cond, NULL)))
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);
mutex_init(&pool->stratum_lock); mutex_init(&pool->stratum_lock);
mutex_init(&pool->gbt_lock); mutex_init(&pool->gbt_lock);
INIT_LIST_HEAD(&pool->curlring); INIT_LIST_HEAD(&pool->curlring);
@ -3165,10 +3166,10 @@ static bool stale_work(struct work *work, bool share)
} }
same_job = true; same_job = true;
mutex_lock(&pool->pool_lock); cg_rlock(&pool->data_lock);
if (strcmp(work->job_id, pool->swork.job_id)) if (strcmp(work->job_id, pool->swork.job_id))
same_job = false; same_job = false;
mutex_unlock(&pool->pool_lock); cg_runlock(&pool->data_lock);
if (!same_job) { if (!same_job) {
applog(LOG_DEBUG, "Work stale due to stratum job_id mismatch"); applog(LOG_DEBUG, "Work stale due to stratum job_id mismatch");
return true; return true;
@ -3310,9 +3311,9 @@ static void *submit_work_thread(void *userdata)
pool->remotefail_occasions++; pool->remotefail_occasions++;
} }
mutex_lock(&pool->pool_lock); cg_rlock(&pool->data_lock);
sessionid_match = (pool->nonce1 && !strcmp(work->nonce1, pool->nonce1)); sessionid_match = (pool->nonce1 && !strcmp(work->nonce1, pool->nonce1));
mutex_unlock(&pool->pool_lock); cg_runlock(&pool->data_lock);
if (!sessionid_match) { if (!sessionid_match) {
applog(LOG_DEBUG, "No matching session id for resubmitting stratum share"); applog(LOG_DEBUG, "No matching session id for resubmitting stratum share");
@ -4873,9 +4874,9 @@ static bool supports_resume(struct pool *pool)
{ {
bool ret; bool ret;
mutex_lock(&pool->pool_lock); cg_rlock(&pool->data_lock);
ret = (pool->sessionid != NULL); ret = (pool->sessionid != NULL);
mutex_unlock(&pool->pool_lock); cg_runlock(&pool->data_lock);
return ret; return ret;
} }
@ -5333,7 +5334,7 @@ static void gen_stratum_work(struct pool *pool, struct work *work)
size_t alloc_len; size_t alloc_len;
int i; int i;
mutex_lock(&pool->pool_lock); cg_wlock(&pool->data_lock);
/* Generate coinbase */ /* Generate coinbase */
work->nonce2 = bin2hex((const unsigned char *)&pool->nonce2, pool->n2size); work->nonce2 = bin2hex((const unsigned char *)&pool->nonce2, pool->n2size);
@ -5386,7 +5387,7 @@ static void gen_stratum_work(struct pool *pool, struct work *work)
work->job_id = strdup(pool->swork.job_id); work->job_id = strdup(pool->swork.job_id);
work->nonce1 = strdup(pool->nonce1); work->nonce1 = strdup(pool->nonce1);
work->ntime = strdup(pool->swork.ntime); work->ntime = strdup(pool->swork.ntime);
mutex_unlock(&pool->pool_lock); cg_wunlock(&pool->data_lock);
applog(LOG_DEBUG, "Generated stratum merkle %s", merkle_hash); applog(LOG_DEBUG, "Generated stratum merkle %s", merkle_hash);
applog(LOG_DEBUG, "Generated stratum header %s", header); applog(LOG_DEBUG, "Generated stratum header %s", header);

1
miner.h

@ -1001,6 +1001,7 @@ struct pool {
char *rpc_proxy; char *rpc_proxy;
pthread_mutex_t pool_lock; pthread_mutex_t pool_lock;
cglock_t data_lock;
struct thread_q *submit_q; struct thread_q *submit_q;
struct thread_q *getwork_q; struct thread_q *getwork_q;

16
util.c

@ -1152,7 +1152,7 @@ static bool parse_notify(struct pool *pool, json_t *val)
goto out; goto out;
} }
mutex_lock(&pool->pool_lock); cg_wlock(&pool->data_lock);
free(pool->swork.job_id); free(pool->swork.job_id);
free(pool->swork.prev_hash); free(pool->swork.prev_hash);
free(pool->swork.coinbase1); free(pool->swork.coinbase1);
@ -1191,7 +1191,7 @@ static bool parse_notify(struct pool *pool, json_t *val)
/* workpadding */ 96; /* workpadding */ 96;
pool->swork.header_len = pool->swork.header_len * 2 + 1; pool->swork.header_len = pool->swork.header_len * 2 + 1;
align_len(&pool->swork.header_len); align_len(&pool->swork.header_len);
mutex_unlock(&pool->pool_lock); cg_wunlock(&pool->data_lock);
if (opt_protocol) { if (opt_protocol) {
applog(LOG_DEBUG, "job_id: %s", job_id); applog(LOG_DEBUG, "job_id: %s", job_id);
@ -1222,9 +1222,9 @@ static bool parse_diff(struct pool *pool, json_t *val)
if (diff == 0) if (diff == 0)
return false; return false;
mutex_lock(&pool->pool_lock); cg_wlock(&pool->data_lock);
pool->swork.diff = diff; pool->swork.diff = diff;
mutex_unlock(&pool->pool_lock); cg_wunlock(&pool->data_lock);
applog(LOG_DEBUG, "Pool %d difficulty set to %f", pool->pool_no, diff); applog(LOG_DEBUG, "Pool %d difficulty set to %f", pool->pool_no, diff);
@ -1599,12 +1599,12 @@ resend:
goto out; goto out;
} }
mutex_lock(&pool->pool_lock); cg_wlock(&pool->data_lock);
pool->sessionid = sessionid; pool->sessionid = sessionid;
pool->nonce1 = nonce1; pool->nonce1 = nonce1;
pool->n1_len = strlen(nonce1) / 2; pool->n1_len = strlen(nonce1) / 2;
pool->n2size = n2size; pool->n2size = n2size;
mutex_unlock(&pool->pool_lock); cg_wunlock(&pool->data_lock);
if (sessionid) if (sessionid)
applog(LOG_DEBUG, "Pool %d stratum session id: %s", pool->pool_no, pool->sessionid); applog(LOG_DEBUG, "Pool %d stratum session id: %s", pool->pool_no, pool->sessionid);
@ -1628,11 +1628,11 @@ out:
/* Reset the sessionid used for stratum resuming in case the pool /* Reset the sessionid used for stratum resuming in case the pool
* does not support it, or does not know how to respond to the * does not support it, or does not know how to respond to the
* presence of the sessionid parameter. */ * presence of the sessionid parameter. */
mutex_lock(&pool->pool_lock); cg_wlock(&pool->data_lock);
free(pool->sessionid); free(pool->sessionid);
free(pool->nonce1); free(pool->nonce1);
pool->sessionid = pool->nonce1 = NULL; pool->sessionid = pool->nonce1 = NULL;
mutex_unlock(&pool->pool_lock); cg_wunlock(&pool->data_lock);
applog(LOG_DEBUG, "Failed to resume stratum, trying afresh"); applog(LOG_DEBUG, "Failed to resume stratum, trying afresh");
noresume = true; noresume = true;
goto resend; goto resend;

Loading…
Cancel
Save