drivers/syslog: add mutex to syslog_default_write
This commit reverts 19f269e54b
and
substitutes the semaphore to a mutex, used as a locking mechanism
to avoid syslog messages being messed.
Considering SMP, threads running on different CPUs could call
syslog_default_write simultaneously. It then calls `up_nputs` that,
in most of the implementations, calls `up_putc` multiple times to
write to the serial. So, calling it at the same would cause syslog
messages to interfere with each other.
`up_nputs` and `up_putc` are low-level functions that could be used
during initialization and by the interrupt handler. Hence, it isn't
advisable to implement any locking mechanism on them. On the other
hand, syslog can also be used from the interrupt: if the interrupt
buffer is selected (`CONFIG_SYSLOG_INTBUFFER=y`), the syslog
messages will be flushed when we aren't serving an interrupt.
On the contrary, if it isn't set, it would call the registered
`sc_force` callback, which calls `syslog_default_putc` instead of
the lock-protected `syslog_default_write`.
This commit is contained in:
parent
441b51b706
commit
71c8265e2d
|
@ -31,6 +31,7 @@
|
|||
|
||||
#include <nuttx/syslog/syslog.h>
|
||||
#include <nuttx/compiler.h>
|
||||
#include <nuttx/mutex.h>
|
||||
|
||||
#ifdef CONFIG_RAMLOG_SYSLOG
|
||||
# include <nuttx/syslog/ramlog.h>
|
||||
|
@ -217,7 +218,13 @@ static ssize_t syslog_default_write(FAR struct syslog_channel_s *channel,
|
|||
FAR const char *buffer, size_t buflen)
|
||||
{
|
||||
#if defined(CONFIG_ARCH_LOWPUTC)
|
||||
static mutex_t lock = NXMUTEX_INITIALIZER;
|
||||
|
||||
nxmutex_lock(&lock);
|
||||
|
||||
up_nputs(buffer, buflen);
|
||||
|
||||
nxmutex_unlock(&lock);
|
||||
#endif
|
||||
|
||||
UNUSED(channel);
|
||||
|
|
Loading…
Reference in New Issue