[rtems commit] posix: replace mmap mappings lock with libio lock
Gedare Bloom
gedare at rtems.org
Mon Jul 24 19:01:25 UTC 2017
Module: rtems
Branch: master
Commit: b264998fa9ef2b048950ba81f3d1615c8f9a182d
Changeset: http://git.rtems.org/rtems/commit/?id=b264998fa9ef2b048950ba81f3d1615c8f9a182d
Author: Gedare Bloom <gedare at rtems.org>
Date: Mon Jul 24 14:46:49 2017 -0400
posix: replace mmap mappings lock with libio lock
Use the libio mutex lock instead of the mmap mappings lock.
Updates #2859.
---
cpukit/posix/include/rtems/posix/mmanimpl.h | 11 +++-
cpukit/posix/src/mmap.c | 82 ++---------------------------
cpukit/posix/src/munmap.c | 6 +--
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 bb33ac9..ff59d91 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 ae68901..8f47d3b 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 6bd79cc..fb9bb87 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 )) {
More information about the vc
mailing list