Browse Source

Check all pools simultaneously at startup switching to the first alive one to speed up startup.

nfactor-troky
Con Kolivas 12 years ago
parent
commit
5221662557
  1. 60
      cgminer.c

60
cgminer.c

@ -6922,9 +6922,43 @@ static void *hotplug_thread(void __maybe_unused *userdata)
} }
#endif #endif
static bool pools_active = false;
static void *test_pool_thread(void *arg)
{
struct pool *pool = (struct pool *)arg;
if (pool_active(pool, false)) {
pool_tset(pool, &pool->lagging);
pool_tclear(pool, &pool->idle);
applog(LOG_INFO, "Pool %d %s active", pool->pool_no, pool->rpc_url);
mutex_lock(&control_lock);
if (!pools_active) {
currentpool = pool;
if (pool->pool_no != 0)
applog(LOG_NOTICE, "Switching to pool %d %s - first alive pool", pool->pool_no, pool->rpc_url);
}
pools_active = true;
mutex_unlock(&control_lock);
}
return NULL;
}
static void probe_pools(void)
{
int i;
for (i = 0; i < total_pools; i++) {
pthread_t *test_thread = malloc(sizeof(pthread_t));
struct pool *pool = pools[i];
pthread_create(test_thread, NULL, test_pool_thread, (void *)pool);
}
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
bool pools_active = false;
struct sigaction handler; struct sigaction handler;
struct thr_info *thr; struct thr_info *thr;
struct block *block; struct block *block;
@ -7299,24 +7333,14 @@ int main(int argc, char *argv[])
applog(LOG_NOTICE, "Probing for an alive pool"); applog(LOG_NOTICE, "Probing for an alive pool");
do { do {
int slept = 0;
/* Look for at least one active pool before starting */ /* Look for at least one active pool before starting */
for (i = 0; i < total_pools; i++) { probe_pools();
struct pool *pool = pools[i]; do {
sleep(1);
if (pool_active(pool, false)) { slept++;
pool_tset(pool, &pool->lagging); } while (!pools_active && slept < 60);
pool_tclear(pool, &pool->idle);
if (!currentpool)
currentpool = pool;
applog(LOG_INFO, "Pool %d %s active", pool->pool_no, pool->rpc_url);
pools_active = true;
break;
} else {
if (pool == currentpool)
currentpool = NULL;
applog(LOG_WARNING, "Unable to get work from pool %d %s", pool->pool_no, pool->rpc_url);
}
}
if (!pools_active) { if (!pools_active) {
applog(LOG_ERR, "No servers were found that could be used to get work from."); applog(LOG_ERR, "No servers were found that could be used to get work from.");

Loading…
Cancel
Save