summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGedare Bloom <gedare@rtems.org>2017-07-24 14:46:49 -0400
committerGedare Bloom <gedare@rtems.org>2017-07-24 14:46:49 -0400
commitb264998fa9ef2b048950ba81f3d1615c8f9a182d (patch)
tree9c9bccd9936c293d6ee47b4c86d80c38c9130db9
parenttmtests/tmcontext01: Prevent GCC 7.1 optimizations (diff)
downloadrtems-b264998fa9ef2b048950ba81f3d1615c8f9a182d.tar.bz2
posix: replace mmap mappings lock with libio lock
Use the libio mutex lock instead of the mmap mappings lock. Updates #2859.
-rw-r--r--cpukit/posix/include/rtems/posix/mmanimpl.h11
-rw-r--r--cpukit/posix/src/mmap.c82
-rw-r--r--cpukit/posix/src/munmap.c6
3 files changed, 13 insertions, 86 deletions
diff --git a/cpukit/posix/include/rtems/posix/mmanimpl.h b/cpukit/posix/include/rtems/posix/mmanimpl.h
index bb33ac97ed..ff59d911ca 100644
--- a/cpukit/posix/include/rtems/posix/mmanimpl.h
+++ b/cpukit/posix/include/rtems/posix/mmanimpl.h
@@ -39,8 +39,15 @@ typedef struct mmap_mappings_s {
extern rtems_chain_control mmap_mappings;
-bool mmap_mappings_lock_obtain( void );
-bool mmap_mappings_lock_release( void );
+static inline void mmap_mappings_lock_obtain( void )
+{
+ rtems_libio_lock();
+}
+
+static inline void mmap_mappings_lock_release( void )
+{
+ rtems_libio_unlock();
+}
#ifdef __cplusplus
}
diff --git a/cpukit/posix/src/mmap.c b/cpukit/posix/src/mmap.c
index ae68901481..8f47d3b6d5 100644
--- a/cpukit/posix/src/mmap.c
+++ b/cpukit/posix/src/mmap.c
@@ -28,85 +28,11 @@
#include <rtems/posix/mmanimpl.h>
#include <rtems/posix/shmimpl.h>
-#define RTEMS_MUTEX_ATTRIBS \
- (RTEMS_PRIORITY | RTEMS_SIMPLE_BINARY_SEMAPHORE | \
- RTEMS_NO_INHERIT_PRIORITY | RTEMS_NO_PRIORITY_CEILING | RTEMS_LOCAL)
/**
- * Mmap chain of mappings.
+ * mmap chain of mappings.
*/
-rtems_chain_control mmap_mappings;
-
-/**
- * The id of the MMAP lock.
- */
-static rtems_id mmap_mappings_lock;
-
-/**
- * Create the lock.
- */
-static
-bool mmap_mappings_lock_create(
- void
-)
-{
- /*
- * Lock the mapping table. We only create a lock if a call is made. First we
- * test if a mapping lock is present. If one is present we lock it. If not
- * the libio lock is locked and we then test the mapping lock again. If not
- * present we create the mapping lock then release libio lock.
- */
- /* FIXME: double-checked locking anti-pattern. */
- if ( mmap_mappings_lock == 0 ) {
- rtems_status_code sc = RTEMS_SUCCESSFUL;
- rtems_chain_initialize_empty( &mmap_mappings );
- rtems_semaphore_obtain( rtems_libio_semaphore,
- RTEMS_WAIT, RTEMS_NO_TIMEOUT );
- /* FIXME: account for semaphore in confdefs, or maybe just use the
- * rtems_libio_semaphore? */
- if ( mmap_mappings_lock == 0 )
- sc = rtems_semaphore_create( rtems_build_name( 'M', 'M', 'A', 'P' ),
- 1,
- RTEMS_MUTEX_ATTRIBS,
- RTEMS_NO_PRIORITY,
- &mmap_mappings_lock );
- rtems_semaphore_release( rtems_libio_semaphore );
- if ( sc != RTEMS_SUCCESSFUL ) {
- errno = EINVAL;
- return false;
- }
- }
- return true;
-}
-
-bool mmap_mappings_lock_obtain(
- void
-)
-{
- if ( mmap_mappings_lock_create( ) ) {
- rtems_status_code sc;
- sc = rtems_semaphore_obtain( mmap_mappings_lock,
- RTEMS_WAIT, RTEMS_NO_TIMEOUT );
- if ( sc != RTEMS_SUCCESSFUL ) {
- errno = EINVAL;
- return false;
- }
- }
- return true;
-}
-
-bool mmap_mappings_lock_release(
- void
-)
-{
- rtems_status_code sc;
- sc = rtems_semaphore_release( mmap_mappings_lock );
- if (( sc != RTEMS_SUCCESSFUL ) && ( errno == 0 )) {
- errno = EINVAL;
- return false;
- }
- return true;
-}
+CHAIN_DEFINE_EMPTY( mmap_mappings );
void *mmap(
void *addr, size_t len, int prot, int flags, int fildes, off_t off
@@ -307,9 +233,7 @@ void *mmap(
return MAP_FAILED;
}
- /* Lock access to mmap_mappings. Sets errno on failure. */
- if ( !mmap_mappings_lock_obtain( ) )
- return MAP_FAILED;
+ mmap_mappings_lock_obtain();
if ( map_fixed ) {
rtems_chain_node* node = rtems_chain_first (&mmap_mappings);
diff --git a/cpukit/posix/src/munmap.c b/cpukit/posix/src/munmap.c
index 6bd79cc0ef..fb9bb872e0 100644
--- a/cpukit/posix/src/munmap.c
+++ b/cpukit/posix/src/munmap.c
@@ -52,11 +52,7 @@ int munmap(void *addr, size_t len)
return -1;
}
- /*
- * Obtain the mmap lock. Sets errno on failure.
- */
- if ( !mmap_mappings_lock_obtain( ))
- return -1;
+ mmap_mappings_lock_obtain();
node = rtems_chain_first (&mmap_mappings);
while ( !rtems_chain_is_tail( &mmap_mappings, node )) {