From 72c4f353e66440896e1aaa1d4b43ca1593bc4634 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Tue, 29 Nov 2016 16:14:20 -0500 Subject: [PATCH] serialqueue: Kick the background thread from serialqueue_exit Wake the background thread up when exiting - as this makes the exit complete faster (and have more predictable timing). Signed-off-by: Kevin O'Connor --- klippy/serialqueue.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/klippy/serialqueue.c b/klippy/serialqueue.c index 444c5ea4..23ed6858 100644 --- a/klippy/serialqueue.c +++ b/klippy/serialqueue.c @@ -448,6 +448,15 @@ check_wake_receive(struct serialqueue *sq) } } +// Write to the internal pipe to wake the background thread if in poll +static void +kick_bg_thread(struct serialqueue *sq) +{ + int ret = write(sq->pipe_fds[1], ".", 1); + if (ret < 0) + report_errno("pipe write", ret); +} + // Update internal state when the receive sequence increases static void update_receive_seq(struct serialqueue *sq, double eventtime, uint64_t rseq) @@ -832,6 +841,7 @@ void serialqueue_exit(struct serialqueue *sq) { pollreactor_do_exit(&sq->pr); + kick_bg_thread(sq); int ret = pthread_join(sq->tid, NULL); if (ret) report_errno("pthread_join", ret); @@ -848,15 +858,6 @@ serialqueue_alloc_commandqueue(void) return cq; } -// Write to the internal pipe to wake the background thread if in poll -static void -kick_bg_thread(struct serialqueue *sq) -{ - int ret = write(sq->pipe_fds[1], ".", 1); - if (ret < 0) - report_errno("pipe write", ret); -} - // Add a batch of messages to the given command_queue void serialqueue_send_batch(struct serialqueue *sq, struct command_queue *cq