forked from Imagelibrary/rtems
libio: Use API mutex
This commit is contained in:
@@ -52,15 +52,6 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
#define F_DUP2FD 20
|
#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
|
* 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;
|
extern pthread_key_t rtems_current_user_env_key;
|
||||||
|
|
||||||
static inline void rtems_libio_lock( void )
|
void rtems_libio_lock( void );
|
||||||
{
|
|
||||||
rtems_semaphore_obtain( rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT );
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void rtems_libio_unlock( void )
|
void rtems_libio_unlock( void );
|
||||||
{
|
|
||||||
rtems_semaphore_release( rtems_libio_semaphore );
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void rtems_filesystem_mt_lock( void )
|
static inline void rtems_filesystem_mt_lock( void )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -18,27 +18,28 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <rtems/libio_.h> /* libio_.h pulls in rtems */
|
#include <rtems/libio_.h>
|
||||||
#include <rtems.h>
|
|
||||||
#include <rtems/assoc.h> /* assoc.h not included by rtems.h */
|
|
||||||
|
|
||||||
#include <stdio.h> /* O_RDONLY, et.al. */
|
#include <pthread.h>
|
||||||
#include <fcntl.h> /* O_RDONLY, et.al. */
|
|
||||||
#include <errno.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/sysinit.h>
|
||||||
|
#include <rtems/score/apimutex.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* File descriptor Table Information
|
* 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;
|
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 )
|
static void rtems_libio_init( void )
|
||||||
{
|
{
|
||||||
rtems_status_code rc;
|
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
rtems_libio_t *iop;
|
rtems_libio_t *iop;
|
||||||
int eno;
|
int eno;
|
||||||
@@ -70,22 +70,6 @@ static void rtems_libio_init( void )
|
|||||||
if (eno != 0) {
|
if (eno != 0) {
|
||||||
_Internal_error( INTERNAL_ERROR_LIBIO_USER_ENV_KEY_CREATE_FAILED );
|
_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(
|
RTEMS_SYSINIT_ITEM(
|
||||||
|
|||||||
@@ -140,11 +140,6 @@ extern rtems_initialization_tasks_table Initialization_tasks[];
|
|||||||
#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 3
|
#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 3
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
|
||||||
* Semaphore count used by the IO library.
|
|
||||||
*/
|
|
||||||
#define _CONFIGURE_LIBIO_SEMAPHORES 1
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* POSIX key count used by the IO library.
|
* POSIX key count used by the IO library.
|
||||||
*/
|
*/
|
||||||
@@ -2120,7 +2115,7 @@ extern rtems_initialization_tasks_table Initialization_tasks[];
|
|||||||
* capabilities.
|
* capabilities.
|
||||||
*/
|
*/
|
||||||
#define _CONFIGURE_SEMAPHORES \
|
#define _CONFIGURE_SEMAPHORES \
|
||||||
(CONFIGURE_MAXIMUM_SEMAPHORES + _CONFIGURE_LIBIO_SEMAPHORES + \
|
(CONFIGURE_MAXIMUM_SEMAPHORES + \
|
||||||
_CONFIGURE_TERMIOS_SEMAPHORES + _CONFIGURE_LIBBLOCK_SEMAPHORES + \
|
_CONFIGURE_TERMIOS_SEMAPHORES + _CONFIGURE_LIBBLOCK_SEMAPHORES + \
|
||||||
_CONFIGURE_SEMAPHORES_FOR_FILE_SYSTEMS + \
|
_CONFIGURE_SEMAPHORES_FOR_FILE_SYSTEMS + \
|
||||||
_CONFIGURE_NETWORKING_SEMAPHORES)
|
_CONFIGURE_NETWORKING_SEMAPHORES)
|
||||||
|
|||||||
@@ -182,7 +182,7 @@ typedef enum {
|
|||||||
INTERNAL_ERROR_RTEMS_INIT_TASK_CREATE_FAILED = 32,
|
INTERNAL_ERROR_RTEMS_INIT_TASK_CREATE_FAILED = 32,
|
||||||
INTERNAL_ERROR_POSIX_INIT_THREAD_CREATE_FAILED = 33,
|
INTERNAL_ERROR_POSIX_INIT_THREAD_CREATE_FAILED = 33,
|
||||||
INTERNAL_ERROR_LIBIO_USER_ENV_KEY_CREATE_FAILED = 34,
|
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_STDOUT_FD_OPEN_FAILED = 36,
|
||||||
INTERNAL_ERROR_LIBIO_STDERR_FD_OPEN_FAILED = 37,
|
INTERNAL_ERROR_LIBIO_STDERR_FD_OPEN_FAILED = 37,
|
||||||
INTERNAL_ERROR_ILLEGAL_USE_OF_FLOATING_POINT_UNIT = 38,
|
INTERNAL_ERROR_ILLEGAL_USE_OF_FLOATING_POINT_UNIT = 38,
|
||||||
|
|||||||
@@ -516,13 +516,13 @@ LAST(RTEMS_SYSINIT_IDLE_THREADS)
|
|||||||
|
|
||||||
FIRST(RTEMS_SYSINIT_LIBIO)
|
FIRST(RTEMS_SYSINIT_LIBIO)
|
||||||
{
|
{
|
||||||
assert(rtems_libio_semaphore == 0);
|
assert(rtems_libio_iop_free_head == NULL);
|
||||||
next_step(LIBIO_PRE);
|
next_step(LIBIO_PRE);
|
||||||
}
|
}
|
||||||
|
|
||||||
LAST(RTEMS_SYSINIT_LIBIO)
|
LAST(RTEMS_SYSINIT_LIBIO)
|
||||||
{
|
{
|
||||||
assert(rtems_libio_semaphore != 0);
|
assert(rtems_libio_iop_free_head == &rtems_libio_iops[0]);
|
||||||
next_step(LIBIO_POST);
|
next_step(LIBIO_POST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user