You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ar...@apache.org on 2024/09/14 05:13:47 UTC

(nuttx) 02/02: ramlog: workaround the unsafe critical section

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

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

commit 981bda5cf09bf166f1d23e6d708c04478f999fdc
Author: ligd <li...@xiaomi.com>
AuthorDate: Thu Jul 25 22:52:52 2024 +0800

    ramlog: workaround the unsafe critical section
    
    thread1:                           thread2:
    ramlog_addbuf()
        enter_critical_section()
        ramlog_pollnotify()
           foreach rl_list
                 --> switch out
                                       ramlog_file_close
                                       enter_critical_section()
                                       list_delete()
                                       leave_critical_section()
                 <--- switch back
           rl_list error
        leave_critical_section()
    
    Signed-off-by: ligd <li...@xiaomi.com>
---
 drivers/syslog/ramlog.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/drivers/syslog/ramlog.c b/drivers/syslog/ramlog.c
index 79d2947452..ba9b3ff849 100644
--- a/drivers/syslog/ramlog.c
+++ b/drivers/syslog/ramlog.c
@@ -337,6 +337,13 @@ static ssize_t ramlog_addbuf(FAR struct ramlog_dev_s *priv,
 
   if (len > 0)
     {
+      /* Lock the scheduler do NOT switch out */
+
+      if (!up_interrupt_context())
+        {
+          sched_lock();
+        }
+
 #ifndef CONFIG_RAMLOG_NONBLOCKING
       /* Are there threads waiting for read data? */
 
@@ -345,6 +352,13 @@ static ssize_t ramlog_addbuf(FAR struct ramlog_dev_s *priv,
       /* Notify all poll/select waiters that they can read from the FIFO */
 
       ramlog_pollnotify(priv);
+
+      /* Unlock the scheduler */
+
+      if (!up_interrupt_context())
+        {
+          sched_unlock();
+        }
     }
 
   /* We always have to return the number of bytes requested and NOT the