From a8866132c2ac2f7ca37e568bd062519b58a211a1 Mon Sep 17 00:00:00 2001 From: Jiuzhu Dong Date: Mon, 28 Feb 2022 21:39:59 +0800 Subject: [PATCH] ramlog: support setting threshold value of ramlog for poll waiters Signed-off-by: Jiuzhu Dong --- 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 ccf65e56f8..9fd74e4e80 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 880ab30671..55cca259bb 100644 --- a/drivers/syslog/ramlog.c +++ b/drivers/syslog/ramlog.c @@ -155,6 +155,16 @@ static struct ramlog_dev_s g_sysdev = * Private Functions ****************************************************************************/ +/**************************************************************************** + * 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 */