logging: Improve algorithm for waking up the thread

Use value returned by atomic_inc to decide on action.
Previously direct value was used and that could lead to
delays in logging processing because thread waking up
could be mishandled.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
Krzysztof Chruscinski 2021-12-29 08:06:05 +01:00 committed by Carles Cufí
commit 8c0a017cd3

View file

@ -226,16 +226,17 @@ static void detect_missed_strdup(struct log_msg *msg)
static void z_log_msg_post_finalize(void) static void z_log_msg_post_finalize(void)
{ {
atomic_inc(&buffered_cnt); atomic_val_t cnt = atomic_inc(&buffered_cnt);
if (panic_mode) { if (panic_mode) {
unsigned int key = irq_lock(); unsigned int key = irq_lock();
(void)log_process(false); (void)log_process(false);
irq_unlock(key); irq_unlock(key);
} else if (proc_tid != NULL && buffered_cnt == 1) { } else if (proc_tid != NULL && cnt == 0) {
k_timer_start(&log_process_thread_timer, k_timer_start(&log_process_thread_timer,
K_MSEC(CONFIG_LOG_PROCESS_THREAD_SLEEP_MS), K_NO_WAIT); K_MSEC(CONFIG_LOG_PROCESS_THREAD_SLEEP_MS), K_NO_WAIT);
} else if (CONFIG_LOG_PROCESS_TRIGGER_THRESHOLD) { } else if (CONFIG_LOG_PROCESS_TRIGGER_THRESHOLD) {
if ((buffered_cnt == CONFIG_LOG_PROCESS_TRIGGER_THRESHOLD) && if ((cnt == CONFIG_LOG_PROCESS_TRIGGER_THRESHOLD) &&
(proc_tid != NULL)) { (proc_tid != NULL)) {
k_timer_stop(&log_process_thread_timer); k_timer_stop(&log_process_thread_timer);
k_sem_give(&log_process_thread_sem); k_sem_give(&log_process_thread_sem);