[PATCH 10/12] RFS: Use self-contained recursive mutex

Sebastian Huber sebastian.huber at embedded-brains.de
Thu Dec 21 14:09:58 UTC 2017


Update #2843.
---
 cpukit/libfs/src/rfs/rtems-rfs-mutex.c | 31 ++-----------------------------
 cpukit/libfs/src/rfs/rtems-rfs-mutex.h | 25 ++++---------------------
 cpukit/sapi/include/confdefs.h         |  9 +--------
 3 files changed, 7 insertions(+), 58 deletions(-)

diff --git a/cpukit/libfs/src/rfs/rtems-rfs-mutex.c b/cpukit/libfs/src/rfs/rtems-rfs-mutex.c
index a320d8093c..9c97c829ed 100644
--- a/cpukit/libfs/src/rfs/rtems-rfs-mutex.c
+++ b/cpukit/libfs/src/rfs/rtems-rfs-mutex.c
@@ -18,30 +18,11 @@
 
 #include <rtems/rfs/rtems-rfs-mutex.h>
 
-#if __rtems__
-/**
- * RTEMS_RFS Mutex Attributes
- */
-#define RTEMS_RFS_MUTEX_ATTRIBS \
-  (RTEMS_PRIORITY | RTEMS_BINARY_SEMAPHORE | \
-   RTEMS_INHERIT_PRIORITY | RTEMS_NO_PRIORITY_CEILING | RTEMS_LOCAL)
-#endif
-
 int
 rtems_rfs_mutex_create (rtems_rfs_mutex* mutex)
 {
 #if __rtems__
-  rtems_status_code sc;
-  sc = rtems_semaphore_create (rtems_build_name ('R', 'F', 'S', 'm'),
-                               1, RTEMS_RFS_MUTEX_ATTRIBS, 0,
-                               mutex);
-  if (sc != RTEMS_SUCCESSFUL)
-  {
-    if (rtems_rfs_trace (RTEMS_RFS_TRACE_MUTEX))
-      printf ("rtems-rfs: mutex: open failed: %s\n",
-              rtems_status_text (sc));
-    return EIO;
-  }
+  rtems_recursive_mutex_init(mutex, "RFS");
 #endif
   return 0;
 }
@@ -50,15 +31,7 @@ int
 rtems_rfs_mutex_destroy (rtems_rfs_mutex* mutex)
 {
 #if __rtems__
-  rtems_status_code sc;
-  sc = rtems_semaphore_delete (*mutex);
-  if (sc != RTEMS_SUCCESSFUL)
-  {
-    if (rtems_rfs_trace (RTEMS_RFS_TRACE_MUTEX))
-      printf ("rtems-rfs: mutex: close failed: %s\n",
-              rtems_status_text (sc));
-    return EIO;
-  }
+  rtems_recursive_mutex_destroy(mutex);
 #endif
   return 0;
 }
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-mutex.h b/cpukit/libfs/src/rfs/rtems-rfs-mutex.h
index 606fd53233..57b58e507e 100644
--- a/cpukit/libfs/src/rfs/rtems-rfs-mutex.h
+++ b/cpukit/libfs/src/rfs/rtems-rfs-mutex.h
@@ -29,13 +29,14 @@
 #if __rtems__
 #include <rtems.h>
 #include <rtems/error.h>
+#include <rtems/thread.h>
 #endif
 
 /**
  * RFS Mutex type.
  */
 #if __rtems__
-typedef rtems_id rtems_rfs_mutex;
+typedef rtems_recursive_mutex rtems_rfs_mutex;
 #else
 typedef uint32_t rtems_rfs_mutex; /* place holder */
 #endif
@@ -73,16 +74,7 @@ static inline int
 rtems_rfs_mutex_lock (rtems_rfs_mutex* mutex)
 {
 #if __rtems__
-  rtems_status_code sc = rtems_semaphore_obtain (*mutex, RTEMS_WAIT, 0);
-  if (sc != RTEMS_SUCCESSFUL)
-  {
-#if RTEMS_RFS_TRACE
-    if (rtems_rfs_trace (RTEMS_RFS_TRACE_MUTEX))
-      printf ("rtems-rfs: mutex: obtain failed: %s\n",
-              rtems_status_text (sc));
-#endif
-    return EIO;
-  }
+  rtems_recursive_mutex_lock(mutex);
 #endif
   return 0;
 }
@@ -99,16 +91,7 @@ static inline int
 rtems_rfs_mutex_unlock (rtems_rfs_mutex* mutex)
 {
 #if __rtems__
-  rtems_status_code sc = rtems_semaphore_release (*mutex);
-  if (sc != RTEMS_SUCCESSFUL)
-  {
-#if RTEMS_RFS_TRACE
-    if (rtems_rfs_trace (RTEMS_RFS_TRACE_MUTEX))
-      printf ("rtems-rfs: mutex: release failed: %s\n",
-              rtems_status_text (sc));
-#endif
-    return EIO;
-  }
+  rtems_recursive_mutex_unlock(mutex);
 #endif
   return 0;
 }
diff --git a/cpukit/sapi/include/confdefs.h b/cpukit/sapi/include/confdefs.h
index e86920b728..329e9f0534 100755
--- a/cpukit/sapi/include/confdefs.h
+++ b/cpukit/sapi/include/confdefs.h
@@ -427,14 +427,8 @@ extern rtems_initialization_tasks_table Initialization_tasks[];
 #if !defined(CONFIGURE_FILESYSTEM_ENTRY_RFS) && \
     defined(CONFIGURE_FILESYSTEM_RFS)
   #include <rtems/rtems-rfs.h>
-  #if !defined(CONFIGURE_MAXIMUM_RFS_MOUNTS)
-    #define CONFIGURE_MAXIMUM_RFS_MOUNTS 1
-  #endif
   #define CONFIGURE_FILESYSTEM_ENTRY_RFS \
     { RTEMS_FILESYSTEM_TYPE_RFS, rtems_rfs_rtems_initialise }
-  #define _CONFIGURE_SEMAPHORES_FOR_RFS CONFIGURE_MAXIMUM_RFS_MOUNTS
-#else
-  #define _CONFIGURE_SEMAPHORES_FOR_RFS 0
 #endif
 
 /**
@@ -453,8 +447,7 @@ extern rtems_initialization_tasks_table Initialization_tasks[];
  */
 #define _CONFIGURE_SEMAPHORES_FOR_FILE_SYSTEMS \
     (_CONFIGURE_SEMAPHORES_FOR_FIFOS + \
-     _CONFIGURE_SEMAPHORES_FOR_NFS + \
-     _CONFIGURE_SEMAPHORES_FOR_RFS)
+     _CONFIGURE_SEMAPHORES_FOR_NFS)
 
 #ifdef CONFIGURE_INIT
 
-- 
2.12.3




More information about the devel mailing list