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 2022/03/28 14:49:05 UTC

[incubator-nuttx] branch master updated: ramlog: support setting threshold value of ramlog for poll waiters

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


The following commit(s) were added to refs/heads/master by this push:
     new a886613  ramlog: support setting threshold value of ramlog for poll waiters
a886613 is described below

commit a8866132c2ac2f7ca37e568bd062519b58a211a1
Author: Jiuzhu Dong <do...@xiaomi.com>
AuthorDate: Mon Feb 28 21:39:59 2022 +0800

    ramlog: support setting threshold value of ramlog for poll waiters
    
    Signed-off-by: Jiuzhu Dong <do...@xiaomi.com>
---
 drivers/syslog/Kconfig  |  6 ++++++
 drivers/syslog/ramlog.c | 21 ++++++++++++++++-----
 2 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/drivers/syslog/Kconfig b/drivers/syslog/Kconfig
index ccf65e5..9fd74e4 100644
--- a/drivers/syslog/Kconfig
+++ b/drivers/syslog/Kconfig
@@ -61,6 +61,12 @@ config RAMLOG_OVERWRITE
 		Enable overwrite of circular buffer. If RAMLOG buffer overflows,
 		overwrite it from the top of buffer and always keep the latest log.
 
+config RAMLOG_POLLTHRESHOLD
+	int "The threshold value of circular buffer to notify poll waiters"
+	default 1
+	---help---
+		When the length of circular buffer exceeds the threshold value, the poll() will
+		return POLLIN to all poll waiters.
 endif
 
 config SYSLOG_BUFFER
diff --git a/drivers/syslog/ramlog.c b/drivers/syslog/ramlog.c
index 880ab30..55cca25 100644
--- a/drivers/syslog/ramlog.c
+++ b/drivers/syslog/ramlog.c
@@ -156,6 +156,16 @@ static struct ramlog_dev_s g_sysdev =
  ****************************************************************************/
 
 /****************************************************************************
+ * Name: ramlog_bufferused
+ ****************************************************************************/
+
+static size_t ramlog_bufferused(FAR struct ramlog_dev_s *priv)
+{
+  return (priv->rl_bufsize + priv->rl_head - priv->rl_tail) %
+         priv->rl_bufsize;
+}
+
+/****************************************************************************
  * Name: ramlog_readnotify
  ****************************************************************************/
 
@@ -408,7 +418,8 @@ static ssize_t ramlog_addbuf(FAR struct ramlog_dev_s *priv,
        * operations a critical section.
        */
 
-      if (readers_waken == 0)
+      if (readers_waken == 0 &&
+          ramlog_bufferused(priv) >= CONFIG_RAMLOG_POLLTHRESHOLD)
         {
           /* Notify all poll/select waiters that they can read from the
            * FIFO.
@@ -633,8 +644,7 @@ static int ramlog_file_ioctl(FAR struct file *filep, int cmd,
   switch (cmd)
     {
       case FIONREAD:
-        *(FAR int *)((uintptr_t)arg) = (priv->rl_bufsize + priv->rl_head -
-                                        priv->rl_tail) % priv->rl_bufsize;
+        *(FAR int *)((uintptr_t)arg) = ramlog_bufferused(priv);
         break;
       default:
         ret = -ENOTTY;
@@ -723,7 +733,7 @@ static int ramlog_file_poll(FAR struct file *filep, FAR struct pollfd *fds,
 
       /* Check if the receive buffer is not empty. */
 
-      if (priv->rl_head != priv->rl_tail)
+      if (ramlog_bufferused(priv) >= CONFIG_RAMLOG_POLLTHRESHOLD)
         {
           eventset |= POLLIN;
         }
@@ -874,7 +884,8 @@ int ramlog_putc(FAR struct syslog_channel_s *channel, int ch)
    * operations a critical section.
    */
 
-  if (readers_waken == 0)
+  if (readers_waken == 0 &&
+      ramlog_bufferused(priv) >= CONFIG_RAMLOG_POLLTHRESHOLD)
     {
       /* Notify all poll/select waiters that they can read from the FIFO */