Browse Source

Bugfix: hash_pop: If a work should be rolled, use a clone of it rather than consume a rollable work

This fixes a bug whereby sufficiently active/fast miners could consume rollable work before the work producing thread had a chance to clone it, effectively making it as useless as an unrollable work.
Luke Dashjr 13 years ago
parent
commit
ae78270155
1 changed files with 10 additions and 0 deletions
  1. 10 0
      cgminer.c

+ 10 - 0
cgminer.c

@@ -4948,6 +4948,7 @@ static struct work *hash_pop(void)
 	struct work *work = NULL, *tmp;
 	int hc;
 
+retry:
 	mutex_lock(stgd_lock);
 	while (!getq->frozen && !HASH_COUNT(staged_work))
 		pthread_cond_wait(&getq->cond, stgd_lock);
@@ -4961,6 +4962,15 @@ static struct work *hash_pop(void)
 		}
 	} else
 		work = staged_work;
+	
+	if (can_roll(work) && should_roll(work))
+	{
+		// Instead of consuming it, force it to be cloned and grab the clone
+		mutex_unlock(stgd_lock);
+		clone_available();
+		goto retry;
+	}
+	
 	HASH_DEL(staged_work, work);
 	if (work_rollable(work))
 		staged_rollable--;