From f16b0a1563c076e75c3cb2c0c205736e2f99732c Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Wed, 23 Aug 2023 10:17:01 -0300 Subject: [PATCH] core/calendar-monitor: Assert more startup conditions The calendar view thread can start spinning its own mainloop before g_thread_new() returns, and in that case we have a NULL thread. Check that either the GThread is what we expect it to be, OR, the thread is NULL and there are no messages in the queue. --- src/core/gcal-calendar-monitor.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/core/gcal-calendar-monitor.c b/src/core/gcal-calendar-monitor.c index b8155ce6..e4b73619 100644 --- a/src/core/gcal-calendar-monitor.c +++ b/src/core/gcal-calendar-monitor.c @@ -848,7 +848,14 @@ message_queue_source_prepare (GSource *source, queue_source = (MessageQueueSource*) source; self = queue_source->monitor; - g_assert (GCAL_IS_THREAD (self->thread)); + /* + * The prepare function can be called before g_thread_new() + * returns, and that's valid. However, in that case, no messages + * should be available in the queue, as the main thread didn't + * return execution to the mainloop yet. Protect against that. + */ + g_assert (GCAL_IS_THREAD (self->thread) || + (!self->thread && g_async_queue_length (self->messages) == 0)); return g_async_queue_length (self->messages) > 0; }