Changeset b264998 in rtems


Ignore:
Timestamp:
Jul 24, 2017, 6:46:49 PM (2 years ago)
Author:
Gedare Bloom <gedare@…>
Branches:
master
Children:
c6d897e5
Parents:
1c256e6
Message:

posix: replace mmap mappings lock with libio lock

Use the libio mutex lock instead of the mmap mappings lock.

Updates #2859.

Location:
cpukit/posix
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • cpukit/posix/include/rtems/posix/mmanimpl.h

    r1c256e6 rb264998  
    4040extern rtems_chain_control mmap_mappings;
    4141
    42 bool mmap_mappings_lock_obtain( void );
    43 bool mmap_mappings_lock_release( void );
     42static inline void mmap_mappings_lock_obtain( void )
     43{
     44  rtems_libio_lock();
     45}
     46
     47static inline void mmap_mappings_lock_release( void )
     48{
     49  rtems_libio_unlock();
     50}
    4451
    4552#ifdef __cplusplus
  • cpukit/posix/src/mmap.c

    r1c256e6 rb264998  
    2929#include <rtems/posix/shmimpl.h>
    3030
    31 #define RTEMS_MUTEX_ATTRIBS \
    32   (RTEMS_PRIORITY | RTEMS_SIMPLE_BINARY_SEMAPHORE | \
    33    RTEMS_NO_INHERIT_PRIORITY | RTEMS_NO_PRIORITY_CEILING | RTEMS_LOCAL)
    3431
    3532/**
    36  * Mmap chain of mappings.
     33 * mmap chain of mappings.
    3734 */
    38 rtems_chain_control mmap_mappings;
    39 
    40 /**
    41  * The id of the MMAP lock.
    42  */
    43 static rtems_id mmap_mappings_lock;
    44 
    45 /**
    46  * Create the lock.
    47  */
    48 static
    49 bool mmap_mappings_lock_create(
    50   void
    51 )
    52 {
    53   /*
    54    * Lock the mapping table. We only create a lock if a call is made. First we
    55    * test if a mapping lock is present. If one is present we lock it. If not
    56    * the libio lock is locked and we then test the mapping lock again. If not
    57    * present we create the mapping lock then release libio lock.
    58    */
    59   /* FIXME: double-checked locking anti-pattern. */
    60   if ( mmap_mappings_lock == 0 ) {
    61     rtems_status_code sc = RTEMS_SUCCESSFUL;
    62     rtems_chain_initialize_empty( &mmap_mappings );
    63     rtems_semaphore_obtain( rtems_libio_semaphore,
    64                             RTEMS_WAIT, RTEMS_NO_TIMEOUT );
    65     /* FIXME: account for semaphore in confdefs, or maybe just use the
    66      * rtems_libio_semaphore? */
    67     if ( mmap_mappings_lock == 0 )
    68       sc = rtems_semaphore_create( rtems_build_name( 'M', 'M', 'A', 'P' ),
    69                                    1,
    70                                    RTEMS_MUTEX_ATTRIBS,
    71                                    RTEMS_NO_PRIORITY,
    72                                    &mmap_mappings_lock );
    73     rtems_semaphore_release( rtems_libio_semaphore );
    74     if ( sc != RTEMS_SUCCESSFUL ) {
    75       errno = EINVAL;
    76       return false;
    77     }
    78   }
    79   return true;
    80 }
    81 
    82 bool mmap_mappings_lock_obtain(
    83   void
    84 )
    85 {
    86   if ( mmap_mappings_lock_create( ) ) {
    87     rtems_status_code sc;
    88     sc = rtems_semaphore_obtain( mmap_mappings_lock,
    89                                  RTEMS_WAIT, RTEMS_NO_TIMEOUT );
    90     if ( sc != RTEMS_SUCCESSFUL ) {
    91       errno = EINVAL;
    92       return false;
    93     }
    94   }
    95   return true;
    96 }
    97 
    98 bool mmap_mappings_lock_release(
    99   void
    100 )
    101 {
    102   rtems_status_code sc;
    103   sc = rtems_semaphore_release( mmap_mappings_lock );
    104   if (( sc != RTEMS_SUCCESSFUL ) && ( errno == 0 )) {
    105     errno = EINVAL;
    106     return false;
    107   }
    108   return true;
    109 }
     35CHAIN_DEFINE_EMPTY( mmap_mappings );
    11036
    11137void *mmap(
     
    308234  }
    309235
    310   /* Lock access to mmap_mappings. Sets errno on failure. */
    311   if ( !mmap_mappings_lock_obtain( ) )
    312     return MAP_FAILED;
     236  mmap_mappings_lock_obtain();
    313237
    314238  if ( map_fixed ) {
  • cpukit/posix/src/munmap.c

    r1c256e6 rb264998  
    5353  }
    5454
    55   /*
    56    * Obtain the mmap lock. Sets errno on failure.
    57    */
    58   if ( !mmap_mappings_lock_obtain( ))
    59     return -1;
     55  mmap_mappings_lock_obtain();
    6056
    6157  node = rtems_chain_first (&mmap_mappings);
Note: See TracChangeset for help on using the changeset viewer.