[rtems commit] libdl: Use self-contained recursive mutex

Sebastian Huber sebh at rtems.org
Thu Feb 8 08:17:37 UTC 2018


Module:    rtems
Branch:    master
Commit:    d9800ac58d8da580053845c61f1633aec4fb107e
Changeset: http://git.rtems.org/rtems/commit/?id=d9800ac58d8da580053845c61f1633aec4fb107e

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Wed Jan  3 06:36:10 2018 +0100

libdl: Use self-contained recursive mutex

Update #2843.

---

 cpukit/include/rtems/rtl/rtl.h      |  9 ++---
 cpukit/libdl/rtl.c                  | 70 +++++++------------------------------
 testsuites/libtests/dl03/dl-cache.c |  2 +-
 3 files changed, 16 insertions(+), 65 deletions(-)

diff --git a/cpukit/include/rtems/rtl/rtl.h b/cpukit/include/rtems/rtl/rtl.h
index fe9a7df..513a674 100644
--- a/cpukit/include/rtems/rtl/rtl.h
+++ b/cpukit/include/rtems/rtl/rtl.h
@@ -20,8 +20,8 @@
 #define _RTEMS_RTL_H_
 
 #include <link.h>
-#include <rtems.h>
 #include <rtems/chain.h>
+#include <rtems/thread.h>
 
 #include <rtems/rtl/rtl-allocator.h>
 #include <rtems/rtl/rtl-fwd.h>
@@ -96,7 +96,7 @@ typedef void (*rtems_rtl_cdtor_t)(void);
  */
 struct rtems_rtl_data_s
 {
-  rtems_id               lock;           /**< The RTL lock id */
+  rtems_recursive_mutex  lock;           /**< The RTL lock */
   rtems_rtl_alloc_data_t allocator;      /**< The allocator data. */
   rtems_chain_control    objects;        /**< List if loaded object files. */
   const char*            paths;          /**< Search paths for archives. */
@@ -183,11 +183,8 @@ rtems_rtl_data_t* rtems_rtl_lock (void);
 
 /**
  * Unlock the Run-time Linker.
- *
- * @return True The RTL is unlocked.
- * @return False The RTL could not be unlocked. Not much you can do.
  */
-bool rtems_rtl_unlock (void);
+void rtems_rtl_unlock (void);
 
 /**
  * Check a pointer is a valid object file descriptor returning the pointer as
diff --git a/cpukit/libdl/rtl.c b/cpukit/libdl/rtl.c
index e2603c8..36641ea 100644
--- a/cpukit/libdl/rtl.c
+++ b/cpukit/libdl/rtl.c
@@ -32,13 +32,6 @@
 #include <rtems/rtl/rtl-trace.h>
 
 /**
- * Semaphore configuration to create a mutex.
- */
-#define RTEMS_MUTEX_ATTRIBS \
-  (RTEMS_PRIORITY | RTEMS_BINARY_SEMAPHORE | \
-   RTEMS_INHERIT_PRIORITY | RTEMS_NO_PRIORITY_CEILING | RTEMS_LOCAL)
-
-/**
  * Symbol table cache size. They can be big so the cache needs space to work.
  */
 #define RTEMS_RTL_ELF_SYMBOL_CACHE (2048)
@@ -92,9 +85,6 @@ rtems_rtl_data_init (void)
 
     if (!rtl)
     {
-      rtems_status_code sc;
-      rtems_id          lock;
-
       /*
        * We cannot set an error in this code because there is no RTL data to
        * hold it.
@@ -129,26 +119,8 @@ rtems_rtl_data_init (void)
       /*
        * Create the RTL lock.
        */
-      sc = rtems_semaphore_create (rtems_build_name ('R', 'T', 'L', 'D'),
-                                   1, RTEMS_MUTEX_ATTRIBS,
-                                   RTEMS_NO_PRIORITY, &lock);
-      if (sc != RTEMS_SUCCESSFUL)
-      {
-        free (rtl);
-        rtems_libio_unlock ();
-        return false;
-      }
-
-      sc = rtems_semaphore_obtain (lock, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
-      if (sc != RTEMS_SUCCESSFUL)
-      {
-        rtems_semaphore_delete (lock);
-        free (rtl);
-        rtems_libio_unlock ();
-        return false;
-      }
-
-      rtl->lock = lock;
+      rtems_recursive_mutex_init (&rtl->lock, "Run-Time Linker");
+      rtems_recursive_mutex_lock (&rtl->lock);
 
       /*
        * Initialise the objects list and create any required services.
@@ -158,7 +130,7 @@ rtems_rtl_data_init (void)
       if (!rtems_rtl_symbol_table_open (&rtl->globals,
                                         RTEMS_RTL_SYMS_GLOBAL_BUCKETS))
       {
-        rtems_semaphore_delete (lock);
+        rtems_recursive_mutex_destroy (&rtl->lock);
         free (rtl);
         rtems_libio_unlock ();
         return false;
@@ -168,7 +140,7 @@ rtems_rtl_data_init (void)
                                             RTEMS_RTL_UNRESOLVED_BLOCK_SIZE))
       {
         rtems_rtl_symbol_table_close (&rtl->globals);
-        rtems_semaphore_delete (lock);
+        rtems_recursive_mutex_destroy (&rtl->lock);
         free (rtl);
         rtems_libio_unlock ();
         return false;
@@ -179,7 +151,7 @@ rtems_rtl_data_init (void)
       {
         rtems_rtl_symbol_table_close (&rtl->globals);
         rtems_rtl_unresolved_table_close (&rtl->unresolved);
-        rtems_semaphore_delete (lock);
+        rtems_recursive_mutex_destroy (&rtl->lock);
         free (rtl);
         rtems_libio_unlock ();
         return false;
@@ -191,7 +163,7 @@ rtems_rtl_data_init (void)
         rtems_rtl_obj_cache_close (&rtl->symbols);
         rtems_rtl_unresolved_table_close (&rtl->unresolved);
         rtems_rtl_symbol_table_close (&rtl->globals);
-        rtems_semaphore_delete (lock);
+        rtems_recursive_mutex_destroy (&rtl->lock);
         free (rtl);
         rtems_libio_unlock ();
         return false;
@@ -204,7 +176,7 @@ rtems_rtl_data_init (void)
         rtems_rtl_obj_cache_close (&rtl->symbols);
         rtems_rtl_unresolved_table_close (&rtl->unresolved);
         rtems_rtl_symbol_table_close (&rtl->globals);
-        rtems_semaphore_delete (lock);
+        rtems_recursive_mutex_destroy (&rtl->lock);
         free (rtl);
         rtems_libio_unlock ();
         return false;
@@ -218,7 +190,7 @@ rtems_rtl_data_init (void)
         rtems_rtl_obj_cache_close (&rtl->symbols);
         rtems_rtl_unresolved_table_close (&rtl->unresolved);
         rtems_rtl_symbol_table_close (&rtl->globals);
-        rtems_semaphore_delete (lock);
+        rtems_recursive_mutex_destroy (&rtl->lock);
         free (rtl);
         rtems_libio_unlock ();
         return false;
@@ -233,7 +205,7 @@ rtems_rtl_data_init (void)
         rtems_rtl_obj_cache_close (&rtl->symbols);
         rtems_rtl_unresolved_table_close (&rtl->unresolved);
         rtems_rtl_symbol_table_close (&rtl->globals);
-        rtems_semaphore_delete (lock);
+        rtems_recursive_mutex_destroy (&rtl->lock);
         free (rtl);
         rtems_libio_unlock ();
         return false;
@@ -343,36 +315,18 @@ rtems_rtl_obj_comp (rtems_rtl_obj_comp_t** decomp,
 rtems_rtl_data_t*
 rtems_rtl_lock (void)
 {
-  rtems_status_code sc;
-
   if (!rtems_rtl_data_init ())
     return NULL;
 
-  sc = rtems_semaphore_obtain (rtl->lock,
-                               RTEMS_WAIT, RTEMS_NO_TIMEOUT);
-  if (sc != RTEMS_SUCCESSFUL)
-  {
-    errno = EINVAL;
-    return NULL;
-  }
+  rtems_recursive_mutex_lock (&rtl->lock);
 
   return rtl;
 }
 
-bool
+void
 rtems_rtl_unlock (void)
 {
-  /*
-   * Not sure any error should be returned or an assert.
-   */
-  rtems_status_code sc;
-  sc = rtems_semaphore_release (rtl->lock);
-  if ((sc != RTEMS_SUCCESSFUL) && (errno == 0))
-  {
-    errno = EINVAL;
-    return false;
-  }
-  return true;
+  rtems_recursive_mutex_unlock (&rtl->lock);
 }
 
 rtems_rtl_obj_t*
diff --git a/testsuites/libtests/dl03/dl-cache.c b/testsuites/libtests/dl03/dl-cache.c
index e11c6b1..82227cb 100644
--- a/testsuites/libtests/dl03/dl-cache.c
+++ b/testsuites/libtests/dl03/dl-cache.c
@@ -75,7 +75,7 @@ static void dl_init_rtl(void)
    */
   rtems_test_assert(rtems_rtl_data () == NULL);
   rtems_test_assert(rtems_rtl_lock () != NULL);
-  rtems_test_assert(rtems_rtl_unlock () == true);
+  rtems_rtl_unlock ();
   rtems_test_assert(rtems_rtl_data () != NULL);
   rtems_rtl_trace_set_mask(RTEMS_RTL_TRACE_ALL | RTEMS_RTL_TRACE_CACHE);
 }



More information about the vc mailing list