From 4967de8621aa38285b62952c4fa6dcb49e255c24 Mon Sep 17 00:00:00 2001 From: hujun5 Date: Tue, 26 Sep 2023 21:12:10 +0800 Subject: [PATCH] ramlog: remove sched_[un]lock and rl_nwaiters Signed-off-by: hujun5 --- drivers/syslog/ramlog.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/drivers/syslog/ramlog.c b/drivers/syslog/ramlog.c index 5776ee6af33eb..bb0ecddee3d34 100644 --- a/drivers/syslog/ramlog.c +++ b/drivers/syslog/ramlog.c @@ -59,9 +59,6 @@ struct ramlog_dev_s { -#ifndef CONFIG_RAMLOG_NONBLOCKING - volatile uint8_t rl_nwaiters; /* Number of threads waiting for data */ -#endif volatile size_t rl_head; /* The head index (where data is added) */ volatile size_t rl_tail; /* The tail index (where data is removed) */ mutex_t rl_lock; /* Enforces mutually exclusive access */ @@ -139,9 +136,6 @@ static char g_sysbuffer[CONFIG_RAMLOG_BUFSIZE]; static struct ramlog_dev_s g_sysdev = { -# ifndef CONFIG_RAMLOG_NONBLOCKING - 0, /* rl_nwaiters */ -# endif CONFIG_RAMLOG_BUFSIZE, /* rl_head */ CONFIG_RAMLOG_BUFSIZE, /* rl_tail */ NXMUTEX_INITIALIZER, /* rl_lock */ @@ -180,8 +174,17 @@ static int ramlog_readnotify(FAR struct ramlog_dev_s *priv) /* Notify all waiting readers that they can read from the FIFO */ flags = enter_critical_section(); - for (i = 0; i < priv->rl_nwaiters; i++) + + for (i = 0; ; i++) { + int semcount = 0; + + sem_getvalue(&priv->rl_waitsem, &semcount); + if (semcount >= 0) + { + break; + } + nxsem_post(&priv->rl_waitsem); } @@ -518,8 +521,6 @@ static ssize_t ramlog_file_read(FAR struct file *filep, FAR char *buffer, * semaphore to wake us up. */ - sched_lock(); - priv->rl_nwaiters++; nxmutex_unlock(&priv->rl_lock); /* We may now be pre-empted! But that should be okay because we @@ -529,13 +530,6 @@ static ssize_t ramlog_file_read(FAR struct file *filep, FAR char *buffer, ret = nxsem_wait(&priv->rl_waitsem); - /* Interrupts will be disabled when we return. So the decrementing - * rl_nwaiters here is safe. - */ - - priv->rl_nwaiters--; - sched_unlock(); - /* Did we successfully get the rl_waitsem? */ if (ret >= 0)