Freeze the queues on all threads that are sent the pause message to prevent them trying to start up again with saved pings in their queues.
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
diff --git a/cgminer.c b/cgminer.c
index b1aaebc..0c455f1 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -1702,6 +1702,7 @@ void kill_work(void)
/* Stop the mining threads*/
for (i = 0; i < mining_threads; i++) {
thr = &thr_info[i];
+ thr_info_freeze(thr);
thr->pause = true;
}
diff --git a/miner.h b/miner.h
index 68ce55b..7550ec7 100644
--- a/miner.h
+++ b/miner.h
@@ -280,6 +280,7 @@ struct thr_info {
extern int thr_info_create(struct thr_info *thr, pthread_attr_t *attr, void *(*start) (void *), void *arg);
extern void thr_info_cancel(struct thr_info *thr);
+extern void thr_info_freeze(struct thr_info *thr);
struct string_elist {
diff --git a/util.c b/util.c
index 1d037bf..9ff5a24 100644
--- a/util.c
+++ b/util.c
@@ -668,13 +668,31 @@ int thr_info_create(struct thr_info *thr, pthread_attr_t *attr, void *(*start) (
return ret;
}
-void thr_info_cancel(struct thr_info *thr)
+void thr_info_freeze(struct thr_info *thr)
{
+ struct tq_ent *ent, *iter;
+ struct thread_q *tq;
+
if (!thr)
return;
- if (thr->q)
- tq_freeze(thr->q);
+ tq = thr->q;
+ if (!tq)
+ return;
+
+ mutex_lock(&tq->mutex);
+ tq->frozen = true;
+ list_for_each_entry_safe(ent, iter, &tq->q, q_node) {
+ list_del(&ent->q_node);
+ free(ent);
+ }
+ mutex_unlock(&tq->mutex);
+}
+
+void thr_info_cancel(struct thr_info *thr)
+{
+ if (!thr)
+ return;
if (PTH(thr) != 0L) {
pthread_cancel(thr->pth);