|
@@ -166,6 +166,9 @@ static pthread_rwlock_t blk_lock;
|
|
|
|
|
|
|
|
pthread_rwlock_t netacc_lock;
|
|
pthread_rwlock_t netacc_lock;
|
|
|
|
|
|
|
|
|
|
+static pthread_mutex_t lp_lock;
|
|
|
|
|
+static pthread_cond_t lp_cond;
|
|
|
|
|
+
|
|
|
double total_mhashes_done;
|
|
double total_mhashes_done;
|
|
|
static struct timeval total_tv_start, total_tv_end;
|
|
static struct timeval total_tv_start, total_tv_end;
|
|
|
|
|
|
|
@@ -2301,6 +2304,10 @@ void switch_pools(struct pool *selected)
|
|
|
mutex_lock(&qd_lock);
|
|
mutex_lock(&qd_lock);
|
|
|
total_queued = 0;
|
|
total_queued = 0;
|
|
|
mutex_unlock(&qd_lock);
|
|
mutex_unlock(&qd_lock);
|
|
|
|
|
+
|
|
|
|
|
+ mutex_lock(&lp_lock);
|
|
|
|
|
+ pthread_cond_broadcast(&lp_cond);
|
|
|
|
|
+ mutex_unlock(&lp_lock);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static void discard_work(struct work *work)
|
|
static void discard_work(struct work *work)
|
|
@@ -4019,6 +4026,20 @@ static struct pool *select_longpoll_pool(struct pool *cp)
|
|
|
return NULL;
|
|
return NULL;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/* This will make the longpoll thread wait till it's the current pool, or it
|
|
|
|
|
+ * has been flagged as rejecting, before attempting to open any connections.
|
|
|
|
|
+ */
|
|
|
|
|
+static void wait_lpcurrent(struct pool *pool)
|
|
|
|
|
+{
|
|
|
|
|
+ if (pool->enabled == POOL_REJECTING)
|
|
|
|
|
+ return;
|
|
|
|
|
+
|
|
|
|
|
+ while (pool != current_pool()) {
|
|
|
|
|
+ mutex_lock(&lp_lock);
|
|
|
|
|
+ pthread_cond_wait(&lp_cond, &lp_lock);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
static void *longpoll_thread(void *userdata)
|
|
static void *longpoll_thread(void *userdata)
|
|
|
{
|
|
{
|
|
|
struct pool *cp = (struct pool *)userdata;
|
|
struct pool *cp = (struct pool *)userdata;
|
|
@@ -4049,6 +4070,8 @@ retry_pool:
|
|
|
/* Any longpoll from any pool is enough for this to be true */
|
|
/* Any longpoll from any pool is enough for this to be true */
|
|
|
have_longpoll = true;
|
|
have_longpoll = true;
|
|
|
|
|
|
|
|
|
|
+ wait_lpcurrent(cp);
|
|
|
|
|
+
|
|
|
if (cp == pool)
|
|
if (cp == pool)
|
|
|
applog(LOG_WARNING, "Long-polling activated for %s", pool->lp_url);
|
|
applog(LOG_WARNING, "Long-polling activated for %s", pool->lp_url);
|
|
|
else
|
|
else
|
|
@@ -4057,6 +4080,8 @@ retry_pool:
|
|
|
while (42) {
|
|
while (42) {
|
|
|
json_t *val, *soval;
|
|
json_t *val, *soval;
|
|
|
|
|
|
|
|
|
|
+ wait_lpcurrent(cp);
|
|
|
|
|
+
|
|
|
gettimeofday(&start, NULL);
|
|
gettimeofday(&start, NULL);
|
|
|
|
|
|
|
|
/* Longpoll connections can be persistent for a very long time
|
|
/* Longpoll connections can be persistent for a very long time
|
|
@@ -4788,6 +4813,10 @@ int main(int argc, char *argv[])
|
|
|
rwlock_init(&blk_lock);
|
|
rwlock_init(&blk_lock);
|
|
|
rwlock_init(&netacc_lock);
|
|
rwlock_init(&netacc_lock);
|
|
|
|
|
|
|
|
|
|
+ mutex_init(&lp_lock);
|
|
|
|
|
+ if (unlikely(pthread_cond_init(&lp_cond, NULL)))
|
|
|
|
|
+ quit(1, "Failed to pthread_cond_init lp_cond");
|
|
|
|
|
+
|
|
|
sprintf(packagename, "%s %s", PACKAGE, VERSION);
|
|
sprintf(packagename, "%s %s", PACKAGE, VERSION);
|
|
|
|
|
|
|
|
#ifdef WANT_CPUMINE
|
|
#ifdef WANT_CPUMINE
|