Check all pools simultaneously at startup switching to the first alive one to speed up startup.
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 69 70 71 72 73 74 75 76 77 78 79 80 81
diff --git a/cgminer.c b/cgminer.c
index 61c5208..2c06ec2 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -6922,9 +6922,43 @@ static void *hotplug_thread(void __maybe_unused *userdata)
}
#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[])
{
- bool pools_active = false;
struct sigaction handler;
struct thr_info *thr;
struct block *block;
@@ -7299,24 +7333,14 @@ int main(int argc, char *argv[])
applog(LOG_NOTICE, "Probing for an alive pool");
do {
+ int slept = 0;
+
/* Look for at least one active pool before starting */
- for (i = 0; i < total_pools; i++) {
- struct pool *pool = pools[i];
-
- if (pool_active(pool, false)) {
- pool_tset(pool, &pool->lagging);
- 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);
- }
- }
+ probe_pools();
+ do {
+ sleep(1);
+ slept++;
+ } while (!pools_active && slept < 60);
if (!pools_active) {
applog(LOG_ERR, "No servers were found that could be used to get work from.");