Commit 9fd60bb53a7bf90f288965c6cdf82110d8b5a5e9

ckolivas 2012-12-24T10:34:06

Merge branch 'master' of github.com:ckolivas/cgminer

diff --git a/cgminer.c b/cgminer.c
index 6025080..f7591e8 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -2998,14 +2998,14 @@ static struct work *make_clone(struct work *work)
 
 static void stage_work(struct work *work);
 
-/* Called with stgd_lock held */
-static bool __clone_available(void)
+static bool clone_available(void)
 {
 	struct work *work, *tmp;
 	bool cloned = false;
 
+	mutex_lock(stgd_lock);
 	if (!staged_rollable)
-		goto out;
+		goto out_unlock;
 
 	HASH_ITER(hh, staged_work, work, tmp) {
 		if (can_roll(work) && should_roll(work)) {
@@ -3021,7 +3021,9 @@ static bool __clone_available(void)
 		}
 	}
 
-out:
+out_unlock:
+	mutex_unlock(stgd_lock);
+
 	return cloned;
 }
 
@@ -6863,7 +6865,7 @@ retry:
 			continue;
 		}
 
-		if (__clone_available()) {
+		if (clone_available()) {
 			applog(LOG_DEBUG, "Cloned getwork work");
 			free_work(work);
 			continue;