Make sure we have work from the current pool somewhere in the queue in case the queue is full of requests from a pool that has just died.
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
diff --git a/cgminer.c b/cgminer.c
index c8da857..b48a911 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -2238,16 +2238,30 @@ static void __inc_queued(void)
total_queued++;
}
-static void __dec_queued(void)
+static int __pool_pending_staged(struct pool *pool)
+{
+ return pool->queued + pool->staged;
+}
+
+static void inc_pool_queued(struct pool *pool)
+{
+ mutex_lock(stgd_lock);
+ pool->queued++;
+ mutex_unlock(stgd_lock);
+}
+
+static void __dec_queued(struct pool *pool)
{
if (total_queued)
total_queued--;
+ if (pool && pool->queued)
+ pool->queued--;
}
static void dec_queued(void)
{
mutex_lock(stgd_lock);
- __dec_queued();
+ __dec_queued(NULL);
mutex_unlock(stgd_lock);
}
@@ -2290,6 +2304,7 @@ static void *get_work_thread(void *userdata)
else {
pool = ret_work->pool = select_pool(wc->lagging);
ce = pop_curl_entry(pool);
+ inc_pool_queued(pool);
/* obtain new work from bitcoin via JSON-RPC */
while (!get_upstream_work(ret_work, ce->curl)) {
@@ -2762,7 +2777,8 @@ static bool hash_push(struct work *work)
mutex_lock(stgd_lock);
if (likely(!getq->frozen)) {
HASH_ADD_INT(staged_work, id, work);
- __dec_queued();
+ work->pool->staged++;
+ __dec_queued(work->pool);
HASH_SORT(staged_work, tv_sort);
} else
rc = false;
@@ -3795,9 +3811,10 @@ static bool clone_available(void)
bool queue_request(struct thr_info *thr, bool needed)
{
+ struct pool *cp = current_pool();
struct workio_cmd *wc;
+ int ps, ts, maxq, pps;
bool lag, ret, qing;
- int ps, ts, maxq;
maxq = opt_queue + mining_threads;
lag = ret = qing = false;
@@ -3806,9 +3823,10 @@ bool queue_request(struct thr_info *thr, bool needed)
__inc_queued();
ps = __pending_staged();
ts = __total_staged();
+ pps = __pool_pending_staged(cp);
mutex_unlock(stgd_lock);
- if (ps >= maxq) {
+ if (pps && ps >= maxq) {
ret = true;
goto out;
}
@@ -3860,6 +3878,7 @@ static struct work *hash_pop(const struct timespec *abstime)
if (worka->clone) {
HASH_DEL(staged_work, worka);
work = worka;
+ work->pool->staged--;
goto out_unlock;
}
}
diff --git a/miner.h b/miner.h
index dc94b5a..5afa071 100644
--- a/miner.h
+++ b/miner.h
@@ -720,6 +720,8 @@ struct pool {
int accepted, rejected;
int seq_rejects;
int solved;
+ int queued;
+ int staged;
bool submit_fail;
bool idle;