[PATCH 2/2] libio: Use API mutex
Sebastian Huber
sebastian.huber at embedded-brains.de
Tue Dec 5 07:01:59 UTC 2017
---
cpukit/libcsupport/include/rtems/libio_.h | 19 ++-----------
cpukit/libcsupport/src/libio_init.c | 44 ++++++++++---------------------
cpukit/sapi/include/confdefs.h | 7 +----
cpukit/score/include/rtems/score/interr.h | 2 +-
testsuites/sptests/spsysinit01/init.c | 4 +--
5 files changed, 20 insertions(+), 56 deletions(-)
diff --git a/cpukit/libcsupport/include/rtems/libio_.h b/cpukit/libcsupport/include/rtems/libio_.h
index 5cc31eed64..414e8a20fc 100644
--- a/cpukit/libcsupport/include/rtems/libio_.h
+++ b/cpukit/libcsupport/include/rtems/libio_.h
@@ -53,15 +53,6 @@ extern "C" {
#define F_DUP2FD 20
/*
- * Semaphore to protect the io table
- */
-
-#define RTEMS_LIBIO_SEM rtems_build_name('L', 'B', 'I', 'O')
-#define RTEMS_LIBIO_IOP_SEM(n) rtems_build_name('L', 'B', 'I', n)
-
-extern rtems_id rtems_libio_semaphore;
-
-/*
* File descriptor Table Information
*/
@@ -347,15 +338,9 @@ void rtems_libio_free_user_env( void *env );
extern pthread_key_t rtems_current_user_env_key;
-static inline void rtems_libio_lock( void )
-{
- rtems_semaphore_obtain( rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT );
-}
+void rtems_libio_lock( void );
-static inline void rtems_libio_unlock( void )
-{
- rtems_semaphore_release( rtems_libio_semaphore );
-}
+void rtems_libio_unlock( void );
static inline void rtems_filesystem_mt_lock( void )
{
diff --git a/cpukit/libcsupport/src/libio_init.c b/cpukit/libcsupport/src/libio_init.c
index 9c24b146ea..5b951ef2be 100644
--- a/cpukit/libcsupport/src/libio_init.c
+++ b/cpukit/libcsupport/src/libio_init.c
@@ -18,27 +18,28 @@
#include "config.h"
#endif
-#include <rtems/libio_.h> /* libio_.h pulls in rtems */
-#include <rtems.h>
-#include <rtems/assoc.h> /* assoc.h not included by rtems.h */
+#include <rtems/libio_.h>
-#include <stdio.h> /* O_RDONLY, et.al. */
-#include <fcntl.h> /* O_RDONLY, et.al. */
-#include <errno.h>
+#include <pthread.h>
-#include <errno.h>
-#include <string.h> /* strcmp */
-#include <unistd.h>
-#include <stdlib.h> /* calloc() */
-
-#include <rtems/libio.h> /* libio.h not pulled in by rtems */
#include <rtems/sysinit.h>
+#include <rtems/score/apimutex.h>
/*
* File descriptor Table Information
*/
-rtems_id rtems_libio_semaphore;
+static API_Mutex_Control rtems_libio_mutex = API_MUTEX_INITIALIZER( "_Libio" );
+
+void rtems_libio_lock( void )
+{
+ _API_Mutex_Lock( &rtems_libio_mutex );
+}
+
+void rtems_libio_unlock( void )
+{
+ _API_Mutex_Unlock( &rtems_libio_mutex );
+}
void *rtems_libio_iop_free_head;
@@ -46,7 +47,6 @@ void **rtems_libio_iop_free_tail = &rtems_libio_iop_free_head;
static void rtems_libio_init( void )
{
- rtems_status_code rc;
uint32_t i;
rtems_libio_t *iop;
int eno;
@@ -70,22 +70,6 @@ static void rtems_libio_init( void )
if (eno != 0) {
_Internal_error( INTERNAL_ERROR_LIBIO_USER_ENV_KEY_CREATE_FAILED );
}
-
- /*
- * Create the binary semaphore used to provide mutual exclusion
- * on the IOP Table.
- */
-
- rc = rtems_semaphore_create(
- RTEMS_LIBIO_SEM,
- 1,
- RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY,
- RTEMS_NO_PRIORITY,
- &rtems_libio_semaphore
- );
- if ( rc != RTEMS_SUCCESSFUL ) {
- _Internal_error( INTERNAL_ERROR_LIBIO_SEM_CREATE_FAILED );
- }
}
RTEMS_SYSINIT_ITEM(
diff --git a/cpukit/sapi/include/confdefs.h b/cpukit/sapi/include/confdefs.h
index 8204f0559f..e94752294b 100755
--- a/cpukit/sapi/include/confdefs.h
+++ b/cpukit/sapi/include/confdefs.h
@@ -141,11 +141,6 @@ extern rtems_initialization_tasks_table Initialization_tasks[];
#endif
/*
- * Semaphore count used by the IO library.
- */
-#define _CONFIGURE_LIBIO_SEMAPHORES 1
-
-/*
* POSIX key count used by the IO library.
*/
#define _CONFIGURE_LIBIO_POSIX_KEYS 1
@@ -2120,7 +2115,7 @@ extern rtems_initialization_tasks_table Initialization_tasks[];
* capabilities.
*/
#define _CONFIGURE_SEMAPHORES \
- (CONFIGURE_MAXIMUM_SEMAPHORES + _CONFIGURE_LIBIO_SEMAPHORES + \
+ (CONFIGURE_MAXIMUM_SEMAPHORES + \
_CONFIGURE_TERMIOS_SEMAPHORES + _CONFIGURE_LIBBLOCK_SEMAPHORES + \
_CONFIGURE_SEMAPHORES_FOR_FILE_SYSTEMS + \
_CONFIGURE_NETWORKING_SEMAPHORES)
diff --git a/cpukit/score/include/rtems/score/interr.h b/cpukit/score/include/rtems/score/interr.h
index a93eaf659c..3144952716 100644
--- a/cpukit/score/include/rtems/score/interr.h
+++ b/cpukit/score/include/rtems/score/interr.h
@@ -182,7 +182,7 @@ typedef enum {
INTERNAL_ERROR_RTEMS_INIT_TASK_CREATE_FAILED = 32,
INTERNAL_ERROR_POSIX_INIT_THREAD_CREATE_FAILED = 33,
INTERNAL_ERROR_LIBIO_USER_ENV_KEY_CREATE_FAILED = 34,
- INTERNAL_ERROR_LIBIO_SEM_CREATE_FAILED = 35,
+ /* INTERNAL_ERROR_LIBIO_SEM_CREATE_FAILED = 35, */
INTERNAL_ERROR_LIBIO_STDOUT_FD_OPEN_FAILED = 36,
INTERNAL_ERROR_LIBIO_STDERR_FD_OPEN_FAILED = 37,
INTERNAL_ERROR_ILLEGAL_USE_OF_FLOATING_POINT_UNIT = 38,
diff --git a/testsuites/sptests/spsysinit01/init.c b/testsuites/sptests/spsysinit01/init.c
index dc09e71e2c..ff6feb066a 100644
--- a/testsuites/sptests/spsysinit01/init.c
+++ b/testsuites/sptests/spsysinit01/init.c
@@ -516,13 +516,13 @@ LAST(RTEMS_SYSINIT_IDLE_THREADS)
FIRST(RTEMS_SYSINIT_LIBIO)
{
- assert(rtems_libio_semaphore == 0);
+ assert(rtems_libio_iop_free_tail == &rtems_libio_iop_free_head);
next_step(LIBIO_PRE);
}
LAST(RTEMS_SYSINIT_LIBIO)
{
- assert(rtems_libio_semaphore != 0);
+ assert(rtems_libio_iop_free_tail != &rtems_libio_iop[0]);
next_step(LIBIO_POST);
}
--
2.12.3
More information about the devel
mailing list