Changeset d9800ac in rtems


Ignore:
Timestamp:
Jan 3, 2018, 5:36:10 AM (19 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
87b7117f
Parents:
0a593c2d
git-author:
Sebastian Huber <sebastian.huber@…> (01/03/18 05:36:10)
git-committer:
Sebastian Huber <sebastian.huber@…> (02/07/18 07:58:30)
Message:

libdl: Use self-contained recursive mutex

Update #2843.

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • cpukit/include/rtems/rtl/rtl.h

    r0a593c2d rd9800ac  
    2121
    2222#include <link.h>
    23 #include <rtems.h>
    2423#include <rtems/chain.h>
     24#include <rtems/thread.h>
    2525
    2626#include <rtems/rtl/rtl-allocator.h>
     
    9797struct rtems_rtl_data_s
    9898{
    99   rtems_id               lock;           /**< The RTL lock id */
     99  rtems_recursive_mutex  lock;           /**< The RTL lock */
    100100  rtems_rtl_alloc_data_t allocator;      /**< The allocator data. */
    101101  rtems_chain_control    objects;        /**< List if loaded object files. */
     
    184184/**
    185185 * Unlock the Run-time Linker.
    186  *
    187  * @return True The RTL is unlocked.
    188  * @return False The RTL could not be unlocked. Not much you can do.
    189  */
    190 bool rtems_rtl_unlock (void);
     186 */
     187void rtems_rtl_unlock (void);
    191188
    192189/**
  • cpukit/libdl/rtl.c

    r0a593c2d rd9800ac  
    3333
    3434/**
    35  * Semaphore configuration to create a mutex.
    36  */
    37 #define RTEMS_MUTEX_ATTRIBS \
    38   (RTEMS_PRIORITY | RTEMS_BINARY_SEMAPHORE | \
    39    RTEMS_INHERIT_PRIORITY | RTEMS_NO_PRIORITY_CEILING | RTEMS_LOCAL)
    40 
    41 /**
    4235 * Symbol table cache size. They can be big so the cache needs space to work.
    4336 */
     
    9386    if (!rtl)
    9487    {
    95       rtems_status_code sc;
    96       rtems_id          lock;
    97 
    9888      /*
    9989       * We cannot set an error in this code because there is no RTL data to
     
    130120       * Create the RTL lock.
    131121       */
    132       sc = rtems_semaphore_create (rtems_build_name ('R', 'T', 'L', 'D'),
    133                                    1, RTEMS_MUTEX_ATTRIBS,
    134                                    RTEMS_NO_PRIORITY, &lock);
    135       if (sc != RTEMS_SUCCESSFUL)
    136       {
    137         free (rtl);
    138         rtems_libio_unlock ();
    139         return false;
    140       }
    141 
    142       sc = rtems_semaphore_obtain (lock, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
    143       if (sc != RTEMS_SUCCESSFUL)
    144       {
    145         rtems_semaphore_delete (lock);
    146         free (rtl);
    147         rtems_libio_unlock ();
    148         return false;
    149       }
    150 
    151       rtl->lock = lock;
     122      rtems_recursive_mutex_init (&rtl->lock, "Run-Time Linker");
     123      rtems_recursive_mutex_lock (&rtl->lock);
    152124
    153125      /*
     
    159131                                        RTEMS_RTL_SYMS_GLOBAL_BUCKETS))
    160132      {
    161         rtems_semaphore_delete (lock);
     133        rtems_recursive_mutex_destroy (&rtl->lock);
    162134        free (rtl);
    163135        rtems_libio_unlock ();
     
    169141      {
    170142        rtems_rtl_symbol_table_close (&rtl->globals);
    171         rtems_semaphore_delete (lock);
     143        rtems_recursive_mutex_destroy (&rtl->lock);
    172144        free (rtl);
    173145        rtems_libio_unlock ();
     
    180152        rtems_rtl_symbol_table_close (&rtl->globals);
    181153        rtems_rtl_unresolved_table_close (&rtl->unresolved);
    182         rtems_semaphore_delete (lock);
     154        rtems_recursive_mutex_destroy (&rtl->lock);
    183155        free (rtl);
    184156        rtems_libio_unlock ();
     
    192164        rtems_rtl_unresolved_table_close (&rtl->unresolved);
    193165        rtems_rtl_symbol_table_close (&rtl->globals);
    194         rtems_semaphore_delete (lock);
     166        rtems_recursive_mutex_destroy (&rtl->lock);
    195167        free (rtl);
    196168        rtems_libio_unlock ();
     
    205177        rtems_rtl_unresolved_table_close (&rtl->unresolved);
    206178        rtems_rtl_symbol_table_close (&rtl->globals);
    207         rtems_semaphore_delete (lock);
     179        rtems_recursive_mutex_destroy (&rtl->lock);
    208180        free (rtl);
    209181        rtems_libio_unlock ();
     
    219191        rtems_rtl_unresolved_table_close (&rtl->unresolved);
    220192        rtems_rtl_symbol_table_close (&rtl->globals);
    221         rtems_semaphore_delete (lock);
     193        rtems_recursive_mutex_destroy (&rtl->lock);
    222194        free (rtl);
    223195        rtems_libio_unlock ();
     
    234206        rtems_rtl_unresolved_table_close (&rtl->unresolved);
    235207        rtems_rtl_symbol_table_close (&rtl->globals);
    236         rtems_semaphore_delete (lock);
     208        rtems_recursive_mutex_destroy (&rtl->lock);
    237209        free (rtl);
    238210        rtems_libio_unlock ();
     
    344316rtems_rtl_lock (void)
    345317{
    346   rtems_status_code sc;
    347 
    348318  if (!rtems_rtl_data_init ())
    349319    return NULL;
    350320
    351   sc = rtems_semaphore_obtain (rtl->lock,
    352                                RTEMS_WAIT, RTEMS_NO_TIMEOUT);
    353   if (sc != RTEMS_SUCCESSFUL)
    354   {
    355     errno = EINVAL;
    356     return NULL;
    357   }
     321  rtems_recursive_mutex_lock (&rtl->lock);
    358322
    359323  return rtl;
    360324}
    361325
    362 bool
     326void
    363327rtems_rtl_unlock (void)
    364328{
    365   /*
    366    * Not sure any error should be returned or an assert.
    367    */
    368   rtems_status_code sc;
    369   sc = rtems_semaphore_release (rtl->lock);
    370   if ((sc != RTEMS_SUCCESSFUL) && (errno == 0))
    371   {
    372     errno = EINVAL;
    373     return false;
    374   }
    375   return true;
     329  rtems_recursive_mutex_unlock (&rtl->lock);
    376330}
    377331
  • testsuites/libtests/dl03/dl-cache.c

    r0a593c2d rd9800ac  
    7676  rtems_test_assert(rtems_rtl_data () == NULL);
    7777  rtems_test_assert(rtems_rtl_lock () != NULL);
    78   rtems_test_assert(rtems_rtl_unlock () == true);
     78  rtems_rtl_unlock ();
    7979  rtems_test_assert(rtems_rtl_data () != NULL);
    8080  rtems_rtl_trace_set_mask(RTEMS_RTL_TRACE_ALL | RTEMS_RTL_TRACE_CACHE);
Note: See TracChangeset for help on using the changeset viewer.