Make pool adding while running asynchronous, using the pool test thread functionality.
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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
diff --git a/cgminer.c b/cgminer.c
index 7736cfd..20c2b06 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -6512,7 +6512,35 @@ char *curses_input(const char *query)
}
#endif
-void add_pool_details(struct pool *pool, bool live, char *url, char *user, char *pass)
+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);
+
+ cg_wlock(&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;
+ }
+ cg_wunlock(&control_lock);
+ pool_resus(pool);
+ } else
+ pool_died(pool);
+
+ return NULL;
+}
+
+/* Always returns true that the pool details were added unless we are not
+ * live, implying this is the only pool being added, so if no pools are
+ * active it returns false. */
+bool add_pool_details(struct pool *pool, bool live, char *url, char *user, char *pass)
{
url = get_proxy(url, pool);
@@ -6524,17 +6552,17 @@ void add_pool_details(struct pool *pool, bool live, char *url, char *user, char
quit(1, "Failed to malloc userpass");
sprintf(pool->rpc_userpass, "%s:%s", pool->rpc_user, pool->rpc_pass);
+ pool->testing = true;
+ pool->idle = true;
enable_pool(pool);
- /* Prevent noise on startup */
- pool->lagging = true;
-
- /* Test the pool is not idle if we're live running, otherwise
- * it will be tested separately */
- if (live && !pool_active(pool, false)) {
- gettimeofday(&pool->tv_idle, NULL);
- pool->idle = true;
+ pthread_create(&pool->test_thread, NULL, test_pool_thread, (void *)pool);
+ if (!live) {
+ pthread_join(pool->test_thread, NULL);
+ pool->testing = false;
+ return pools_active;
}
+ return true;
}
#ifdef HAVE_CURSES
@@ -6574,8 +6602,7 @@ static bool input_pool(bool live)
url = httpinput;
}
- add_pool_details(pool, live, url, user, pass);
- ret = true;
+ ret = add_pool_details(pool, live, url, user, pass);
out:
immedok(logwin, false);
@@ -6988,31 +7015,6 @@ 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);
-
- cg_wlock(&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;
- }
- cg_wunlock(&control_lock);
- pool_resus(pool);
- } else
- pool_died(pool);
-
- return NULL;
-}
-
static void probe_pools(void)
{
int i;
diff --git a/miner.h b/miner.h
index 5581316..20ef31c 100644
--- a/miner.h
+++ b/miner.h
@@ -849,7 +849,7 @@ extern int enabled_pools;
extern bool detect_stratum(struct pool *pool, char *url);
extern void print_summary(void);
extern struct pool *add_pool(void);
-extern void add_pool_details(struct pool *pool, bool live, char *url, char *user, char *pass);
+extern bool add_pool_details(struct pool *pool, bool live, char *url, char *user, char *pass);
#define MAX_GPUDEVICES 16
diff --git a/util.c b/util.c
index c4fb95a..4428199 100644
--- a/util.c
+++ b/util.c
@@ -1398,7 +1398,7 @@ bool auth_stratum(struct pool *pool)
ss = json_dumps(err_val, JSON_INDENT(3));
else
ss = strdup("(unknown reason)");
- applog(LOG_WARNING, "JSON stratum auth failed: %s", ss);
+ applog(LOG_WARNING, "pool %d JSON stratum auth failed: %s", pool->pool_no, ss);
free(ss);
goto out;