Skip to content

Commit

Permalink
ramlog: remove sched_[un]lock and rl_nwaiters
Browse files Browse the repository at this point in the history
Signed-off-by: hujun5 <[email protected]>
  • Loading branch information
hujun260 authored and xiaoxiang781216 committed Oct 12, 2023
1 parent 3d6e893 commit 4967de8
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions drivers/syslog/ramlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 4967de8

Please sign in to comment.