Browse Source

Abstract pool_actively_in_use to handle multipool checking for multiple uses

Luke Dashjr 12 years ago
parent
commit
831f7b1295
1 changed files with 20 additions and 15 deletions
  1. 20 15
      miner.c

+ 20 - 15
miner.c

@@ -4346,7 +4346,7 @@ out:
 }
 }
 
 
 /* Specifies whether we can use this pool for work or not. */
 /* Specifies whether we can use this pool for work or not. */
-static bool pool_unworkable(struct pool *pool)
+static bool pool_unworkable(const struct pool * const pool)
 {
 {
 	if (pool->idle)
 	if (pool->idle)
 		return true;
 		return true;
@@ -4357,6 +4357,18 @@ static bool pool_unworkable(struct pool *pool)
 	return false;
 	return false;
 }
 }
 
 
+static
+bool pool_actively_in_use(const struct pool * const pool, const struct pool *cp)
+{
+	if (pool_unworkable(pool))
+		return false;
+	if (pool_strategy == POOL_LOADBALANCE || pool_strategy == POOL_BALANCE)
+		return true;
+	if (!cp)
+		cp = current_pool();
+	return (pool == cp);
+}
+
 /* In balanced mode, the amount of diff1 solutions per pool is monitored as a
 /* In balanced mode, the amount of diff1 solutions per pool is monitored as a
  * rolling average per 10 minutes and if pools start getting more, it biases
  * rolling average per 10 minutes and if pools start getting more, it biases
  * away from them to distribute work evenly. The share count is reset to the
  * away from them to distribute work evenly. The share count is reset to the
@@ -4462,7 +4474,7 @@ retry:
 		pool = cp;
 		pool = cp;
 
 
 out:
 out:
-	if (cp != pool && !(pool_strategy == POOL_LOADBALANCE  || pool_strategy == POOL_BALANCE))
+	if (!pool_actively_in_use(pool, cp))
 	{
 	{
 		if (!pool_active(pool, false))
 		if (!pool_active(pool, false))
 		{
 		{
@@ -4988,7 +5000,7 @@ static inline bool should_roll(struct work *work)
 	struct timeval now;
 	struct timeval now;
 	time_t expiry;
 	time_t expiry;
 
 
-	if (work->pool != current_pool() && pool_strategy != POOL_LOADBALANCE && pool_strategy != POOL_BALANCE)
+	if (!pool_actively_in_use(work->pool, NULL))
 		return false;
 		return false;
 
 
 	if (stale_work(work, false))
 	if (stale_work(work, false))
@@ -5270,8 +5282,8 @@ bool stale_work(struct work *work, bool share)
 
 
 	/* If the user only wants strict failover, any work from a pool other than
 	/* If the user only wants strict failover, any work from a pool other than
 	 * the current one is always considered stale */
 	 * the current one is always considered stale */
-	if (opt_fail_only && !share && pool != current_pool() && !work->mandatory &&
-	    pool_strategy != POOL_LOADBALANCE && pool_strategy != POOL_BALANCE) {
+	if (opt_fail_only && !share && !work->mandatory && !pool_actively_in_use(pool, NULL))
+	{
 		applog(LOG_DEBUG, "Work stale due to fail only pool mismatch (pool %u vs %u)", pool->pool_no, current_pool()->pool_no);
 		applog(LOG_DEBUG, "Work stale due to fail only pool mismatch (pool %u vs %u)", pool->pool_no, current_pool()->pool_no);
 		return true;
 		return true;
 	}
 	}
@@ -8120,12 +8132,6 @@ static bool cnx_needed(struct pool *pool)
 	if (pool->enabled != POOL_ENABLED)
 	if (pool->enabled != POOL_ENABLED)
 		return false;
 		return false;
 
 
-	/* Balance strategies need all pools online */
-	if (pool_strategy == POOL_BALANCE)
-		return true;
-	if (pool_strategy == POOL_LOADBALANCE)
-		return true;
-
 	/* Idle stratum pool needs something to kick it alive again */
 	/* Idle stratum pool needs something to kick it alive again */
 	if (pool->has_stratum && pool->idle)
 	if (pool->has_stratum && pool->idle)
 		return true;
 		return true;
@@ -8133,7 +8139,7 @@ static bool cnx_needed(struct pool *pool)
 	/* Getwork pools without opt_fail_only need backup pools up to be able
 	/* Getwork pools without opt_fail_only need backup pools up to be able
 	 * to leak shares */
 	 * to leak shares */
 	cp = current_pool();
 	cp = current_pool();
-	if (cp == pool)
+	if (pool_actively_in_use(pool, cp))
 		return true;
 		return true;
 	if (!pool_localgen(cp) && (!opt_fail_only || !cp->hdr_path))
 	if (!pool_localgen(cp) && (!opt_fail_only || !cp->hdr_path))
 		return true;
 		return true;
@@ -9445,9 +9451,8 @@ static struct pool *select_longpoll_pool(struct pool *cp)
  */
  */
 static void wait_lpcurrent(struct pool *pool)
 static void wait_lpcurrent(struct pool *pool)
 {
 {
-	while (!cnx_needed(pool) && (pool->enabled == POOL_DISABLED ||
-	       (pool != current_pool() && pool_strategy != POOL_LOADBALANCE &&
-	       pool_strategy != POOL_BALANCE))) {
+	while ((!cnx_needed(pool)) && !pool_actively_in_use(pool, NULL))
+	{
 		mutex_lock(&lp_lock);
 		mutex_lock(&lp_lock);
 		pthread_cond_wait(&lp_cond, &lp_lock);
 		pthread_cond_wait(&lp_cond, &lp_lock);
 		mutex_unlock(&lp_lock);
 		mutex_unlock(&lp_lock);