Browse Source

Merge commit '26ddd1f' into cg_merges_20130513

Conflicts:
	miner.c
	util.c
Luke Dashjr 12 years ago
parent
commit
613ecb407e
3 changed files with 16 additions and 14 deletions
  1. 9 8
      miner.c
  2. 1 0
      miner.h
  3. 6 6
      util.c

+ 9 - 8
miner.c

@@ -499,6 +499,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);
 	INIT_LIST_HEAD(&pool->curlring);
 	pool->swork.transparency_time = (time_t)-1;
@@ -3870,10 +3871,10 @@ bool stale_work(struct work *work, bool share)
 		}
 
 		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;
@@ -4181,11 +4182,11 @@ static void *submit_work_thread(__maybe_unused void *userdata)
 			int fd = pool->sock;
 			bool sessionid_match;
 			
-			mutex_lock(&pool->pool_lock);
+			cg_rlock(&pool->data_lock);
 			// NOTE: cgminer only does this check on retries, but BFGMiner does it for even the first/normal submit; therefore, it needs to be such that it always is true on the same connection regardless of session management
 			// NOTE: Worst case scenario for a false positive: the pool rejects it as H-not-zero
 			sessionid_match = (!pool->nonce1) || !strcmp(work->nonce1, pool->nonce1);
-			mutex_unlock(&pool->pool_lock);
+			cg_runlock(&pool->data_lock);
 			if (!sessionid_match)
 			{
 				applog(LOG_DEBUG, "No matching session id for resubmitting stratum share");
@@ -6186,9 +6187,9 @@ static bool supports_resume(struct pool *pool)
 {
 	bool ret;
 
-	mutex_lock(&pool->pool_lock);
+	cg_rlock(&pool->data_lock);
 	ret = (pool->sessionid != NULL);
-	mutex_unlock(&pool->pool_lock);
+	cg_runlock(&pool->data_lock);
 	return ret;
 }
 
@@ -6690,7 +6691,7 @@ static void gen_stratum_work(struct pool *pool, struct work *work)
 
 	clean_work(work);
 
-	mutex_lock(&pool->pool_lock);
+	cg_wlock(&pool->data_lock);
 
 	/* Generate coinbase */
 	work->nonce2 = bin2hex((const unsigned char *)&pool->nonce2, pool->n2size);
@@ -6743,7 +6744,7 @@ static void gen_stratum_work(struct pool *pool, struct work *work)
 	work->job_id = strdup(pool->swork.job_id);
 	work->nonce1 = strdup(pool->nonce1);
 	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

@@ -1076,6 +1076,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;

+ 6 - 6
util.c

@@ -1473,7 +1473,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);
@@ -1513,7 +1513,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);
 
 	applog(LOG_DEBUG, "Received stratum notify from pool %u with job_id=%s",
 	       pool->pool_no, job_id);
@@ -1551,9 +1551,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 stratum bdifficulty set to %f", pool->pool_no, diff);
 
@@ -1980,14 +1980,14 @@ resend:
 		goto out;
 	}
 
-	mutex_lock(&pool->pool_lock);
+	cg_wlock(&pool->data_lock);
 	free(pool->sessionid);
 	pool->sessionid = sessionid;
 	free(pool->nonce1);
 	pool->nonce1 = nonce1;
 	pool->n1_len = strlen(nonce1) / 2;
 	pool->n2size = n2size;
-	mutex_unlock(&pool->pool_lock);
+	cg_wunlock(&pool->data_lock);
 
 	if (sessionid)
 		applog(LOG_DEBUG, "Pool %d stratum session id: %s", pool->pool_no, pool->sessionid);