You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ma...@apache.org on 2021/03/04 04:00:41 UTC

[incubator-nuttx] 01/01: Revert "libs: misc: Remove critical section in lib_filesem.c for SMP"

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

masayuki pushed a commit to branch revert-2938-lib_filesem
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit d6f350ae23e0436435902cf777302ad5240e848f
Author: Masayuki Ishikawa <ma...@gmail.com>
AuthorDate: Thu Mar 4 13:00:32 2021 +0900

    Revert "libs: misc: Remove critical section in lib_filesem.c for SMP"
    
    This reverts commit 191ada2296b9fed543f678e2f0501f388b1f8024.
---
 libs/libc/misc/lib_filesem.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/libs/libc/misc/lib_filesem.c b/libs/libc/misc/lib_filesem.c
index 480d35c..5550d06 100644
--- a/libs/libc/misc/lib_filesem.c
+++ b/libs/libc/misc/lib_filesem.c
@@ -47,6 +47,10 @@
 #include <nuttx/semaphore.h>
 #include <nuttx/fs/fs.h>
 
+#ifdef CONFIG_SMP
+#  include <nuttx/irq.h>
+#endif
+
 #include "libc.h"
 
 #ifndef CONFIG_STDIO_DISABLE_BUFFERING
@@ -77,6 +81,10 @@ void lib_sem_initialize(FAR struct file_struct *stream)
 
 void lib_take_semaphore(FAR struct file_struct *stream)
 {
+#ifdef CONFIG_SMP
+  irqstate_t flags = enter_critical_section();
+#endif
+
   pid_t my_pid = getpid();
   int ret;
 
@@ -108,6 +116,10 @@ void lib_take_semaphore(FAR struct file_struct *stream)
       stream->fs_holder = my_pid;
       stream->fs_counts = 1;
     }
+
+#ifdef CONFIG_SMP
+  leave_critical_section(flags);
+#endif
 }
 
 /****************************************************************************
@@ -116,6 +128,10 @@ void lib_take_semaphore(FAR struct file_struct *stream)
 
 void lib_give_semaphore(FAR struct file_struct *stream)
 {
+#ifdef CONFIG_SMP
+  irqstate_t flags = enter_critical_section();
+#endif
+
   /* I better be holding at least one reference to the semaphore */
 
   DEBUGASSERT(stream->fs_holder == getpid());
@@ -136,6 +152,10 @@ void lib_give_semaphore(FAR struct file_struct *stream)
       stream->fs_counts = 0;
       DEBUGVERIFY(_SEM_POST(&stream->fs_sem));
     }
+
+#ifdef CONFIG_SMP
+  leave_critical_section(flags);
+#endif
 }
 
 #endif /* CONFIG_STDIO_DISABLE_BUFFERING */