diff --git a/cgminer.c b/cgminer.c index c0a0ccd2..0b5f20ef 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;