Browse Source

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

Con Kolivas 13 years ago
parent
commit
2aa47b761b
3 changed files with 10 additions and 8 deletions
  1. 5 4
      cgminer.c
  2. 1 0
      miner.h
  3. 4 4
      util.c

+ 5 - 4
cgminer.c

@@ -431,6 +431,7 @@ struct pool *add_pool(void)
 	mutex_init(&pool->pool_lock);
 	if (unlikely(pthread_cond_init(&pool->cr_cond, NULL)))
 		quit(1, "Failed to pthread_cond_init in add_pool");
+	cglock_init(&pool->data_lock);
 	mutex_init(&pool->stratum_lock);
 	mutex_init(&pool->gbt_lock);
 	INIT_LIST_HEAD(&pool->curlring);
@@ -3077,10 +3078,10 @@ static bool stale_work(struct work *work, bool share)
 	if (!share && pool->has_stratum) {
 		bool same_job = true;
 
-		mutex_lock(&pool->pool_lock);
+		cg_rlock(&pool->data_lock);
 		if (strcmp(work->job_id, pool->swork.job_id))
 			same_job = false;
-		mutex_unlock(&pool->pool_lock);
+		cg_runlock(&pool->data_lock);
 		if (!same_job) {
 			applog(LOG_DEBUG, "Work stale due to stratum job_id mismatch");
 			return true;
@@ -5128,7 +5129,7 @@ static void gen_stratum_work(struct pool *pool, struct work *work)
 	size_t alloc_len;
 	int i;
 
-	mutex_lock(&pool->pool_lock);
+	cg_wlock(&pool->data_lock);
 
 	/* Generate coinbase */
 	work->nonce2 = bin2hex((const unsigned char *)&pool->nonce2, pool->n2size);
@@ -5181,7 +5182,7 @@ static void gen_stratum_work(struct pool *pool, struct work *work)
 	work->job_id = strdup(pool->swork.job_id);
 	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 header %s", header);

+ 1 - 0
miner.h

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

+ 4 - 4
util.c

@@ -1126,7 +1126,7 @@ static bool parse_notify(struct pool *pool, json_t *val)
 		goto out;
 	}
 
-	mutex_lock(&pool->pool_lock);
+	cg_wlock(&pool->data_lock);
 	free(pool->swork.job_id);
 	free(pool->swork.prev_hash);
 	free(pool->swork.coinbase1);
@@ -1165,7 +1165,7 @@ static bool parse_notify(struct pool *pool, json_t *val)
 	/* workpadding */	 96;
 	pool->swork.header_len = pool->swork.header_len * 2 + 1;
 	align_len(&pool->swork.header_len);
-	mutex_unlock(&pool->pool_lock);
+	cg_wunlock(&pool->data_lock);
 
 	if (opt_protocol) {
 		applog(LOG_DEBUG, "job_id: %s", job_id);
@@ -1196,9 +1196,9 @@ static bool parse_diff(struct pool *pool, json_t *val)
 	if (diff == 0)
 		return false;
 
-	mutex_lock(&pool->pool_lock);
+	cg_wlock(&pool->data_lock);
 	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);