shell: logging: Fix assertion when shell is overflowed with logging
When shell had too many pending log messages it was attempting to drop expired messages and retrying to put the new message. There was an assumption that enough messages are dropped and new message can be put. It may not be the case if no message expired during given time. Wrapped the operation in loop to continue until expired message is freed and new message is enqueued. Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
parent
a09b5ade26
commit
9a85a89313
1 changed files with 23 additions and 22 deletions
|
@ -92,11 +92,14 @@ static void msg_to_fifo(const struct shell *shell,
|
|||
struct log_msg *msg)
|
||||
{
|
||||
int err;
|
||||
bool cont;
|
||||
struct shell_log_backend_msg t_msg = {
|
||||
.msg = msg,
|
||||
.timestamp = k_uptime_get_32()
|
||||
};
|
||||
|
||||
do {
|
||||
cont = false;
|
||||
err = k_msgq_put(shell->log_backend->msgq, &t_msg,
|
||||
K_MSEC(shell->log_backend->timeout));
|
||||
|
||||
|
@ -106,15 +109,12 @@ static void msg_to_fifo(const struct shell *shell,
|
|||
case -EAGAIN:
|
||||
case -ENOMSG:
|
||||
{
|
||||
/* Attempt to drop old message. */
|
||||
flush_expired_messages(shell);
|
||||
|
||||
err = k_msgq_put(shell->log_backend->msgq, &msg, K_NO_WAIT);
|
||||
if (err) {
|
||||
/* Unexpected case as we just freed one element and
|
||||
* there is no other context that puts into the msgq.
|
||||
*/
|
||||
__ASSERT_NO_MSG(0);
|
||||
}
|
||||
/* Retry putting message. */
|
||||
cont = true;
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -122,6 +122,7 @@ static void msg_to_fifo(const struct shell *shell,
|
|||
__ASSERT_NO_MSG(0);
|
||||
break;
|
||||
}
|
||||
} while (cont);
|
||||
}
|
||||
|
||||
void z_shell_log_backend_disable(const struct shell_log_backend *backend)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue