Find the first usable pool in preference to the current pool in select_pool for work.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
diff --git a/cgminer.c b/cgminer.c
index c0a0ccd..0b5f20e 100644
--- a/cgminer.c
+++ b/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;