Browse Source

Find the first usable pool in preference to the current pool in select_pool for work.

Con Kolivas 13 years ago
parent
commit
1468feb0d3
1 changed files with 19 additions and 13 deletions
  1. 19 13
      cgminer.c

+ 19 - 13
cgminer.c

@@ -2618,11 +2618,23 @@ static struct pool *select_balanced(struct pool *cp)
 	return ret;
 }
 
+static bool pool_unusable(struct pool *pool)
+{
+	if (pool->idle)
+		return true;
+	if (pool->enabled != POOL_ENABLED)
+		return true;
+	if (pool->has_stratum && !pool->stratum_active)
+		return true;
+	return false;
+}
+
 /* Select any active pool in a rotating fashion when loadbalance is chosen */
 static inline struct pool *select_pool(bool lagging)
 {
 	static int rotating_pool = 0;
 	struct pool *pool, *cp;
+	int tested;
 
 	cp = current_pool();
 
@@ -2634,14 +2646,19 @@ static inline struct pool *select_pool(bool lagging)
 	else
 		pool = NULL;
 
-	while (!pool) {
+	/* Try to find the first pool in the rotation that is usable */
+	tested = 0;
+	while (!pool && tested++ < total_pools) {
 		if (++rotating_pool >= total_pools)
 			rotating_pool = 0;
 		pool = pools[rotating_pool];
-		if ((!pool->idle && pool->enabled == POOL_ENABLED) || pool == cp)
+		if (!pool_unusable(pool))
 			break;
 		pool = NULL;
 	}
+	/* If still nothing is usable, use the current pool */
+	if (!pool)
+		pool = cp;
 
 	return pool;
 }
@@ -3358,17 +3375,6 @@ static struct pool *priority_pool(int choice)
 
 static void clear_pool_work(struct pool *pool);
 
-static bool pool_unusable(struct pool *pool)
-{
-	if (pool->idle)
-		return true;
-	if (pool->enabled != POOL_ENABLED)
-		return true;
-	if (pool->has_stratum && !pool->stratum_active)
-		return true;
-	return false;
-}
-
 void switch_pools(struct pool *selected)
 {
 	struct pool *pool, *last_pool;