You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2021/07/03 16:24:29 UTC

[incubator-nuttx] 01/03: syslog/default_channel: fix log confusion when multi task writing together

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit b30bf4ff064b3ef20f0ed131d701f4db408492cb
Author: Jiuzhu Dong <do...@xiaomi.com>
AuthorDate: Thu Jun 10 22:05:58 2021 +0800

    syslog/default_channel: fix log confusion when multi task writing together
    
    Signed-off-by: Jiuzhu Dong <do...@xiaomi.com>
---
 drivers/syslog/syslog_channel.c | 30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)

diff --git a/drivers/syslog/syslog_channel.c b/drivers/syslog/syslog_channel.c
index 2cedae2..2357993 100644
--- a/drivers/syslog/syslog_channel.c
+++ b/drivers/syslog/syslog_channel.c
@@ -56,10 +56,12 @@
 #if defined(CONFIG_SYSLOG_DEFAULT)
 static int syslog_default_putc(FAR struct syslog_channel_s *channel,
                                int ch);
+static ssize_t syslog_default_write(FAR struct syslog_channel_s *channel,
+                                    FAR const char *buffer, size_t buflen);
 #endif
 
 /****************************************************************************
- * Public Data
+ * Private Data
  ****************************************************************************/
 
 #if defined(CONFIG_RAMLOG_SYSLOG)
@@ -91,10 +93,14 @@ static struct syslog_channel_s g_rpmsg_channel =
 #endif
 
 #if defined(CONFIG_SYSLOG_DEFAULT)
+static sem_t g_syslog_default_sem = SEM_INITIALIZER(1);
+
 static const struct syslog_channel_ops_s g_default_channel_ops =
 {
   syslog_default_putc,
-  syslog_default_putc
+  syslog_default_putc,
+  NULL,
+  syslog_default_write
 };
 
 static struct syslog_channel_s g_default_channel =
@@ -126,7 +132,7 @@ FAR struct syslog_channel_s
  ****************************************************************************/
 
 /****************************************************************************
- * Name: syslog_default_putc and syslog_default_flush
+ * Name: syslog_default_putc
  *
  * Description:
  *   If the arch supports a low-level putc function, output will be
@@ -145,6 +151,24 @@ static int syslog_default_putc(FAR struct syslog_channel_s *channel, int ch)
 
   return ch;
 }
+
+static ssize_t syslog_default_write(FAR struct syslog_channel_s *channel,
+                                    FAR const char *buffer, size_t buflen)
+{
+#if defined(CONFIG_ARCH_LOWPUTC)
+  size_t nwritten;
+
+  nxsem_wait(&g_syslog_default_sem);
+  for (nwritten = 0; nwritten < buflen; nwritten++)
+    {
+      up_putc(buffer[nwritten]);
+    }
+
+  nxsem_post(&g_syslog_default_sem);
+#endif
+
+  return OK;
+}
 #endif
 
 /****************************************************************************