aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/serialqueue.c
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2016-11-29 16:22:54 -0500
committerKevin O'Connor <kevin@koconnor.net>2016-11-29 21:58:48 -0500
commit0d43d269ede949fac1e4b5bb125514a240ec3efe (patch)
tree2e4e3916350ecdc3cef62bab540e11f9fedf8776 /klippy/serialqueue.c
parenta0829c63ded2b039e4aa0cc2ba5b5ca343a8ff82 (diff)
downloadkutter-0d43d269ede949fac1e4b5bb125514a240ec3efe.tar.gz
kutter-0d43d269ede949fac1e4b5bb125514a240ec3efe.tar.xz
kutter-0d43d269ede949fac1e4b5bb125514a240ec3efe.zip
serialhdl: Fully deallocate serialqueue on disconnect
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/serialqueue.c')
-rw-r--r--klippy/serialqueue.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/klippy/serialqueue.c b/klippy/serialqueue.c
index 23ed6858..6c1b9d63 100644
--- a/klippy/serialqueue.c
+++ b/klippy/serialqueue.c
@@ -438,6 +438,18 @@ debug_queue_add(struct list_head *root, struct queue_message *qm)
message_free(old);
}
+// Free all the messages on a queue
+static void
+queue_free(struct list_head *root)
+{
+ while (!list_empty(root)) {
+ struct queue_message *qm = list_first_entry(
+ root, struct queue_message, node);
+ list_del(&qm->node);
+ message_free(qm);
+ }
+}
+
// Wake up the receiver thread if it is waiting
static void
check_wake_receive(struct serialqueue *sq)
@@ -847,6 +859,28 @@ serialqueue_exit(struct serialqueue *sq)
report_errno("pthread_join", ret);
}
+// Free all resources associated with a serialqueue
+void
+serialqueue_free(struct serialqueue *sq)
+{
+ if (!pollreactor_is_exit(&sq->pr))
+ serialqueue_exit(sq);
+ pthread_mutex_lock(&sq->lock);
+ queue_free(&sq->sent_queue);
+ queue_free(&sq->receive_queue);
+ queue_free(&sq->old_sent);
+ queue_free(&sq->old_receive);
+ while (!list_empty(&sq->pending_queues)) {
+ struct command_queue *cq = list_first_entry(
+ &sq->pending_queues, struct command_queue, node);
+ list_del(&cq->node);
+ queue_free(&cq->ready_queue);
+ queue_free(&cq->stalled_queue);
+ }
+ pthread_mutex_unlock(&sq->lock);
+ free(sq);
+}
+
// Allocate a 'struct command_queue'
struct command_queue *
serialqueue_alloc_commandqueue(void)