From c904df573396d95957dc79b242b3a76911063089 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Fri, 18 Mar 2016 07:25:23 +0100 Subject: score: Add _Objects_Get_by_name() Replace _Objects_Name_to_id_string() with _Objects_Get_by_name() since all users of this function are interested in the object itself and not the identifier. Use the object allocator lock to protect the search. Update #2555. --- cpukit/posix/src/mqueueopen.c | 18 ++++++++--------- cpukit/posix/src/mqueueunlink.c | 35 ++++++++------------------------ cpukit/posix/src/psxnametoid.c | 44 +++++------------------------------------ cpukit/posix/src/semopen.c | 18 ++++++++--------- cpukit/posix/src/semunlink.c | 28 +++++--------------------- 5 files changed, 36 insertions(+), 107 deletions(-) (limited to 'cpukit/posix/src') diff --git a/cpukit/posix/src/mqueueopen.c b/cpukit/posix/src/mqueueopen.c index 005de74158..d327e13fac 100644 --- a/cpukit/posix/src/mqueueopen.c +++ b/cpukit/posix/src/mqueueopen.c @@ -67,11 +67,10 @@ mqd_t mq_open( va_list arg; struct mq_attr *attr = NULL; int status; - Objects_Id the_mq_id; POSIX_Message_queue_Control *the_mq; POSIX_Message_queue_Control_fd *the_mq_fd; - Objects_Locations location; size_t name_len; + Objects_Get_by_name_error error; if ( oflag & O_CREAT ) { va_start(arg, oflag); @@ -87,7 +86,7 @@ mqd_t mq_open( } the_mq_fd->oflag = oflag; - status = _POSIX_Message_queue_Name_to_id( name, &the_mq_id, &name_len ); + the_mq = _POSIX_Message_queue_Get_by_name( name, &name_len, &error ); /* * If the name to id translation worked, then the message queue exists @@ -95,15 +94,18 @@ mqd_t mq_open( * need to check to see if this is a "message queue does not exist" * or some other miscellaneous error on the name. */ - if ( status ) { + if ( the_mq == NULL ) { /* * Unless provided a valid name that did not already exist * and we are willing to create then it is an error. */ - if ( !( status == ENOENT && (oflag & O_CREAT) ) ) { + if ( !( error == OBJECTS_GET_BY_NAME_NO_OBJECT && (oflag & O_CREAT) ) ) { _POSIX_Message_queue_Free_fd( the_mq_fd ); _Objects_Allocator_unlock(); - rtems_set_errno_and_return_value( status, MQ_OPEN_FAILED ); + rtems_set_errno_and_return_value( + _POSIX_Get_by_name_error( error ), + MQ_OPEN_FAILED + ); } } else { /* name -> ID translation succeeded */ @@ -120,7 +122,6 @@ mqd_t mq_open( * In this case we need to do an ID->pointer conversion to * check the mode. */ - the_mq = _POSIX_Message_queue_Get( the_mq_id, &location ); the_mq->open_count += 1; the_mq_fd->Queue = the_mq; _Objects_Open_string( @@ -128,7 +129,6 @@ mqd_t mq_open( &the_mq_fd->Object, NULL ); - _Thread_Enable_dispatch(); _Objects_Allocator_unlock(); return the_mq_fd->Object.id; @@ -149,7 +149,7 @@ mqd_t mq_open( /* * errno was set by Create_support, so don't set it again. */ - if ( status == -1 ) { + if ( status != 0 ) { _POSIX_Message_queue_Free_fd( the_mq_fd ); _Objects_Allocator_unlock(); return MQ_OPEN_FAILED; diff --git a/cpukit/posix/src/mqueueunlink.c b/cpukit/posix/src/mqueueunlink.c index 2be096a421..d5182d21fc 100644 --- a/cpukit/posix/src/mqueueunlink.c +++ b/cpukit/posix/src/mqueueunlink.c @@ -18,19 +18,10 @@ #include "config.h" #endif -#include - -#include -#include -#include -#include #include -#include -#include -#include -#include #include +#include /* * 15.2.2 Remove a Message Queue, P1003.1b-1993, p. 276 @@ -40,31 +31,21 @@ int mq_unlink( const char *name ) { - int status; - POSIX_Message_queue_Control *the_mq; - Objects_Id the_mq_id; - size_t name_len; + POSIX_Message_queue_Control *the_mq; + Objects_Get_by_name_error error; _Objects_Allocator_lock(); - _Thread_Disable_dispatch(); - status = _POSIX_Message_queue_Name_to_id( name, &the_mq_id, &name_len ); - if ( status != 0 ) { - _Thread_Enable_dispatch(); + the_mq = _POSIX_Message_queue_Get_by_name( name, NULL, &error ); + if ( the_mq == NULL ) { _Objects_Allocator_unlock(); - rtems_set_errno_and_return_minus_one( status ); - } - - the_mq = (POSIX_Message_queue_Control *) _Objects_Get_local_object( - &_POSIX_Message_queue_Information, - _Objects_Get_index( the_mq_id ) - ); + rtems_set_errno_and_return_minus_one( _POSIX_Get_by_name_error( error ) ); + } the_mq->linked = false; _POSIX_Message_queue_Namespace_remove( the_mq ); _POSIX_Message_queue_Delete( the_mq ); - _Thread_Enable_dispatch(); - _Objects_Allocator_unlock(); + _Objects_Allocator_unlock(); return 0; } diff --git a/cpukit/posix/src/psxnametoid.c b/cpukit/posix/src/psxnametoid.c index 637de91212..eac8e84611 100644 --- a/cpukit/posix/src/psxnametoid.c +++ b/cpukit/posix/src/psxnametoid.c @@ -20,44 +20,10 @@ #include -#include -#include #include -/* pure ANSI mode does not have this prototype */ -size_t strnlen(const char *, size_t); - -int _POSIX_Name_to_id( - Objects_Information *information, - const char *name, - Objects_Id *id, - size_t *len -) -{ - int eno = EINVAL; - size_t n = 0; - - if ( name != NULL && name [0] != '\0' ) { - n = strnlen( name, NAME_MAX ); - - if ( n < NAME_MAX ) { - Objects_Name_or_id_lookup_errors status = _Objects_Name_to_id_string( - information, - name, - id - ); - - if ( status == OBJECTS_NAME_OR_ID_LOOKUP_SUCCESSFUL ) { - eno = 0; - } else { - eno = ENOENT; - } - } else { - eno = ENAMETOOLONG; - } - } - - *len = n; - - return eno; -} +const int _POSIX_Get_by_name_error_table[ 3 ] = { + EINVAL, + ENAMETOOLONG, + ENOENT +}; diff --git a/cpukit/posix/src/semopen.c b/cpukit/posix/src/semopen.c index fe0dbebe7f..b844b08bb4 100644 --- a/cpukit/posix/src/semopen.c +++ b/cpukit/posix/src/semopen.c @@ -60,10 +60,9 @@ sem_t *sem_open( va_list arg; unsigned int value = 0; int status; - Objects_Id the_semaphore_id; POSIX_Semaphore_Control *the_semaphore; - Objects_Locations location; size_t name_len; + Objects_Get_by_name_error error; if ( oflag & O_CREAT ) { va_start(arg, oflag); @@ -73,7 +72,7 @@ sem_t *sem_open( } _Objects_Allocator_lock(); - status = _POSIX_Semaphore_Name_to_id( name, &the_semaphore_id, &name_len ); + the_semaphore = _POSIX_Semaphore_Get_by_name( name, &name_len, &error ); /* * If the name to id translation worked, then the semaphore exists @@ -82,16 +81,19 @@ sem_t *sem_open( * or some other miscellaneous error on the name. */ - if ( status ) { + if ( the_semaphore == NULL ) { /* * Unless provided a valid name that did not already exist * and we are willing to create then it is an error. */ - if ( !( status == ENOENT && (oflag & O_CREAT) ) ) { + if ( !( error == OBJECTS_GET_BY_NAME_NO_OBJECT && (oflag & O_CREAT) ) ) { _Objects_Allocator_unlock(); - rtems_set_errno_and_return_value( status, SEM_FAILED ); + rtems_set_errno_and_return_value( + _POSIX_Get_by_name_error( error ), + SEM_FAILED + ); } } else { @@ -104,9 +106,7 @@ sem_t *sem_open( rtems_set_errno_and_return_value( EEXIST, SEM_FAILED ); } - the_semaphore = _POSIX_Semaphore_Get( (sem_t *) &the_semaphore_id, &location ); the_semaphore->open_count += 1; - _Thread_Enable_dispatch(); _Objects_Allocator_unlock(); goto return_id; } @@ -130,7 +130,7 @@ sem_t *sem_open( _Objects_Allocator_unlock(); - if ( status == -1 ) + if ( status != 0 ) return SEM_FAILED; return_id: diff --git a/cpukit/posix/src/semunlink.c b/cpukit/posix/src/semunlink.c index 863d25801d..b8406185d4 100644 --- a/cpukit/posix/src/semunlink.c +++ b/cpukit/posix/src/semunlink.c @@ -18,15 +18,8 @@ #include "config.h" #endif -#include - -#include -#include -#include #include -#include -#include #include #include @@ -34,32 +27,21 @@ int sem_unlink( const char *name ) { - int status; - POSIX_Semaphore_Control *the_semaphore; - Objects_Id the_semaphore_id; - size_t name_len; + POSIX_Semaphore_Control *the_semaphore; + Objects_Get_by_name_error error; _Objects_Allocator_lock(); - _Thread_Disable_dispatch(); - status = _POSIX_Semaphore_Name_to_id( name, &the_semaphore_id, &name_len ); - if ( status != 0 ) { - _Thread_Enable_dispatch(); + the_semaphore = _POSIX_Semaphore_Get_by_name( name, NULL, &error ); + if ( the_semaphore == NULL ) { _Objects_Allocator_unlock(); - rtems_set_errno_and_return_minus_one( status ); + rtems_set_errno_and_return_minus_one( _POSIX_Get_by_name_error( error ) ); } - the_semaphore = (POSIX_Semaphore_Control *) _Objects_Get_local_object( - &_POSIX_Semaphore_Information, - _Objects_Get_index( the_semaphore_id ) - ); - the_semaphore->linked = false; _POSIX_Semaphore_Namespace_remove( the_semaphore ); _POSIX_Semaphore_Delete( the_semaphore ); - _Thread_Enable_dispatch(); _Objects_Allocator_unlock(); - return 0; } -- cgit v1.2.3