Set the lp_sent variable under lock since there will almost always be a race on setting this variable, potentially leading to multiple LPs being sent out.
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
diff --git a/cgminer.c b/cgminer.c
index 0e2d449..24bc050 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -336,7 +336,7 @@ static bool pool_tset(struct pool *pool, bool *var)
return ret;
}
-static bool pool_tclear(struct pool *pool, bool *var)
+bool pool_tclear(struct pool *pool, bool *var)
{
bool ret;
@@ -1592,10 +1592,10 @@ static bool get_upstream_work(struct work *work, bool lagging)
/* If this is the current pool and supports longpoll but has not sent
* a longpoll, send one now */
- if (unlikely(pool == current_pool() && !pool->is_lp && pool->hdr_path && !pool->lp_sent)) {
- pool->lp_sent = true;
- req_longpoll = true;
- url = pool->lp_url;
+ if (unlikely(!pool->is_lp && pool == current_pool() && pool->hdr_path &&
+ !pool_tset(pool, &pool->lp_sent))) {
+ req_longpoll = true;
+ url = pool->lp_url;
}
retry:
diff --git a/miner.h b/miner.h
index c383f91..37a8f9c 100644
--- a/miner.h
+++ b/miner.h
@@ -601,6 +601,7 @@ extern void switch_pools(struct pool *selected);
extern void write_config(FILE *fcfg);
extern void log_curses(int prio, const char *f, va_list ap);
extern void clear_logwin(void);
+extern bool pool_tclear(struct pool *pool, bool *var);
extern struct thread_q *tq_new(void);
extern void tq_free(struct thread_q *tq);
extern bool tq_push(struct thread_q *tq, void *data);
diff --git a/util.c b/util.c
index 594ba87..525bfa5 100644
--- a/util.c
+++ b/util.c
@@ -351,7 +351,7 @@ json_t *json_rpc_call(CURL *curl, const char *url,
rc = curl_easy_perform(curl);
if (longpoll)
- pool->lp_sent = false;
+ pool_tclear(pool, &pool->lp_sent);
if (rc) {
applog(LOG_INFO, "HTTP request failed: %s", curl_err_str);
goto err_out;