logging: Fix tracking of buffered messages

Algorithm was failing in case when overflow mode was enabled
but allocation of new message failed. It could happen if message
size exceeded buffer size. Losing track of buffered messages
can lead to logging processing freeze.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
Krzysztof Chruscinski 2022-01-19 14:45:41 +01:00 committed by Anas Nashif
commit 18165b1d49
4 changed files with 13 additions and 7 deletions

View file

@ -847,10 +847,12 @@ uint32_t z_vrfy_log_buffered_cnt(void)
#include <syscalls/log_buffered_cnt_mrsh.c>
#endif
void z_log_dropped(void)
void z_log_dropped(bool buffered)
{
atomic_inc(&dropped_cnt);
atomic_dec(&buffered_cnt);
if (buffered) {
atomic_dec(&buffered_cnt);
}
}
uint32_t z_log_dropped_read_and_clear(void)
@ -869,7 +871,7 @@ static void notify_drop(const struct mpsc_pbuf_buffer *buffer,
ARG_UNUSED(buffer);
ARG_UNUSED(item);
z_log_dropped();
z_log_dropped(true);
}