Skip to content

Commit

Permalink
xtensa/nputs: add a mutex to prevent concurrent tasks from writing
Browse files Browse the repository at this point in the history
Considering SMP, multiples CPU would be able to call up_nputs
simultaneously. This function is most used by syslog and, in spite
of the syslog supporting buffered output, the implementation of
the up_nputs allows multiple threads to run concurrently, messing
with the log messages.

Please check apache#6618 for more
information about the locking mechanism.
  • Loading branch information
tmedicci committed May 26, 2023
1 parent c904b16 commit 70e49aa
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions arch/xtensa/src/common/xtensa_nputs.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include <nuttx/config.h>
#include <nuttx/arch.h>
#include <nuttx/mutex.h>

/****************************************************************************
* Public Functions
Expand All @@ -39,8 +40,14 @@

void up_nputs(const char *str, size_t len)
{
static mutex_t lock = NXMUTEX_INITIALIZER;

nxmutex_lock(&lock);

while (len-- > 0 && *str)
{
up_putc(*str++);
}

nxmutex_unlock(&lock);
}

0 comments on commit 70e49aa

Please sign in to comment.