From 5f60164a0fc36484b60004310320dfd6f3ef0525 Mon Sep 17 00:00:00 2001 From: Krzysztof Chruscinski Date: Mon, 11 Jul 2022 11:25:54 +0200 Subject: [PATCH] logging: Prevent redundant thread wake up Fix a bug introduced by 658123bb21 where if all backends were ready prior to logging thread loop, thread was periodically waken up for no reason. Fix is setting timeout to K_FOREVER if all backends are ready after the initialization. Signed-off-by: Krzysztof Chruscinski --- subsys/logging/log_core.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/subsys/logging/log_core.c b/subsys/logging/log_core.c index 4531c2b2923..9a47fa3c35e 100644 --- a/subsys/logging/log_core.c +++ b/subsys/logging/log_core.c @@ -644,7 +644,11 @@ static void log_process_thread_func(void *dummy1, void *dummy2, void *dummy3) __ASSERT_NO_MSG(log_backend_count_get() > 0); uint32_t activate_mask = z_log_init(false, false); - k_timeout_t timeout = K_MSEC(50); /* Arbitrary value */ + /* If some backends are not activated yet set periodical thread wake up + * to poll backends for readiness. Period is set arbitrary. + * If all backends are ready periodic wake up is not needed. + */ + k_timeout_t timeout = (activate_mask != 0) ? K_MSEC(50) : K_FOREVER; bool processed_any = false; thread_set(k_current_get()); @@ -656,6 +660,9 @@ static void log_process_thread_func(void *dummy1, void *dummy2, void *dummy3) if (activate_mask) { activate_mask = activate_foreach_backend(activate_mask); if (!activate_mask) { + /* Periodic wake up no longer needed since all + * backends are ready. + */ timeout = K_FOREVER; } }