From 53092d19211054d67787990714798c2e72c8a623 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Fri, 26 Apr 2002 23:39:01 +0000 Subject: 2001-04-26 Joel Sherrill * include/rtems/posix/mqueue.h, inline/rtems/posix/mqueue.inl, src/mqueue.c, src/mqueueclose.c, src/mqueuecreatesupp.c, src/mqueuegetattr.c, src/mqueuenotify.c, src/mqueueopen.c, src/mqueuerecvsupp.c, src/mqueuesendsupp.c, src/mqueuesetattr.c: Per PR81 reworked to add a message queue descriptor separate from the underlying message queue. This allows non-blocking to follow the "open" not the underlying queue. --- c/src/exec/posix/src/mqueue.c | 10 +++++++ c/src/exec/posix/src/mqueueclose.c | 23 +++++++++++++-- c/src/exec/posix/src/mqueuecreatesupp.c | 7 +++-- c/src/exec/posix/src/mqueuegetattr.c | 12 ++++---- c/src/exec/posix/src/mqueuenotify.c | 9 ++++-- c/src/exec/posix/src/mqueueopen.c | 52 +++++++++++++++++++++++---------- c/src/exec/posix/src/mqueuerecvsupp.c | 15 ++++++---- c/src/exec/posix/src/mqueuesendsupp.c | 16 +++++----- c/src/exec/posix/src/mqueuesetattr.c | 33 +++++---------------- 9 files changed, 107 insertions(+), 70 deletions(-) (limited to 'c/src/exec/posix/src') diff --git a/c/src/exec/posix/src/mqueue.c b/c/src/exec/posix/src/mqueue.c index 5fda3bf2cd..5d3c39bd72 100644 --- a/c/src/exec/posix/src/mqueue.c +++ b/c/src/exec/posix/src/mqueue.c @@ -58,4 +58,14 @@ void _POSIX_Message_queue_Manager_initialization( _POSIX_PATH_MAX, FALSE ); + _Objects_Initialize_information( + &_POSIX_Message_queue_Information_fds, + OBJECTS_POSIX_MESSAGE_QUEUE_FDS, + FALSE, + maximum_message_queues, + sizeof( POSIX_Message_queue_Control_fd ), + FALSE, + 0, + FALSE + ); } diff --git a/c/src/exec/posix/src/mqueueclose.c b/c/src/exec/posix/src/mqueueclose.c index 80da647116..e809eac3ec 100644 --- a/c/src/exec/posix/src/mqueueclose.c +++ b/c/src/exec/posix/src/mqueueclose.c @@ -41,10 +41,11 @@ int mq_close( mqd_t mqdes ) { - register POSIX_Message_queue_Control *the_mq; - Objects_Locations location; + POSIX_Message_queue_Control *the_mq; + POSIX_Message_queue_Control_fd *the_mq_fd; + Objects_Locations location; - the_mq = _POSIX_Message_queue_Get( mqdes, &location ); + the_mq_fd = _POSIX_Message_queue_Get_fd( mqdes, &location ); switch ( location ) { case OBJECTS_ERROR: rtems_set_errno_and_return_minus_one( EBADF ); @@ -53,8 +54,24 @@ int mq_close( return POSIX_MP_NOT_IMPLEMENTED(); rtems_set_errno_and_return_minus_one( EINVAL ); case OBJECTS_LOCAL: + /* + * First update the actual message queue to reflect this descriptor + * being disassociated. This may result in the queue being really + * deleted. + */ + + the_mq = the_mq_fd->Queue; the_mq->open_count -= 1; _POSIX_Message_queue_Delete( the_mq ); + + /* + * Now close this file descriptor. + */ + + _Objects_Close( + &_POSIX_Message_queue_Information_fds, &the_mq_fd->Object ); + _POSIX_Message_queue_Free_fd( the_mq_fd ); + _Thread_Enable_dispatch(); return 0; } diff --git a/c/src/exec/posix/src/mqueuecreatesupp.c b/c/src/exec/posix/src/mqueuecreatesupp.c index ce9a4bcb29..35b3e1b826 100644 --- a/c/src/exec/posix/src/mqueuecreatesupp.c +++ b/c/src/exec/posix/src/mqueuecreatesupp.c @@ -41,9 +41,8 @@ */ int _POSIX_Message_queue_Create_support( - const char *name, + const char *_name, int pshared, - unsigned int oflag, struct mq_attr *attr_ptr, POSIX_Message_queue_Control **message_queue ) @@ -51,6 +50,7 @@ int _POSIX_Message_queue_Create_support( POSIX_Message_queue_Control *the_mq; CORE_message_queue_Attributes *the_mq_attr; struct mq_attr attr; + char *name; _Thread_Disable_dispatch(); @@ -95,7 +95,6 @@ int _POSIX_Message_queue_Create_support( } the_mq->process_shared = pshared; - the_mq->oflag = oflag; the_mq->named = TRUE; the_mq->open_count = 1; the_mq->linked = TRUE; @@ -133,6 +132,8 @@ int _POSIX_Message_queue_Create_support( rtems_set_errno_and_return_minus_one( ENOSPC ); } + name = malloc(256); + strcpy( name, _name ); _Objects_Open( &_POSIX_Message_queue_Information, &the_mq->Object, diff --git a/c/src/exec/posix/src/mqueuegetattr.c b/c/src/exec/posix/src/mqueuegetattr.c index 3152611300..80be6335c7 100644 --- a/c/src/exec/posix/src/mqueuegetattr.c +++ b/c/src/exec/posix/src/mqueuegetattr.c @@ -42,14 +42,15 @@ int mq_getattr( struct mq_attr *mqstat ) { - register POSIX_Message_queue_Control *the_mq; + POSIX_Message_queue_Control *the_mq; + POSIX_Message_queue_Control_fd *the_mq_fd; Objects_Locations location; CORE_message_queue_Attributes *the_mq_attr; if ( !mqstat ) rtems_set_errno_and_return_minus_one( EINVAL ); - the_mq = _POSIX_Message_queue_Get( mqdes, &location ); + the_mq_fd = _POSIX_Message_queue_Get_fd( mqdes, &location ); switch ( location ) { case OBJECTS_ERROR: rtems_set_errno_and_return_minus_one( EBADF ); @@ -58,16 +59,15 @@ int mq_getattr( return POSIX_MP_NOT_IMPLEMENTED(); rtems_set_errno_and_return_minus_one( EINVAL ); case OBJECTS_LOCAL: + the_mq = the_mq_fd->Queue; + /* * Return the old values. */ - /* XXX this is the same stuff as is in mq_setattr... and probably */ - /* XXX should be in an inlined private routine */ - the_mq_attr = &the_mq->Message_queue.Attributes; - mqstat->mq_flags = the_mq->oflag; + mqstat->mq_flags = the_mq_fd->oflag; mqstat->mq_msgsize = the_mq->Message_queue.maximum_message_size; mqstat->mq_maxmsg = the_mq->Message_queue.maximum_pending_messages; mqstat->mq_curmsgs = the_mq->Message_queue.number_of_pending_messages; diff --git a/c/src/exec/posix/src/mqueuenotify.c b/c/src/exec/posix/src/mqueuenotify.c index 35a1e1deca..93e24ac71f 100644 --- a/c/src/exec/posix/src/mqueuenotify.c +++ b/c/src/exec/posix/src/mqueuenotify.c @@ -64,10 +64,11 @@ int mq_notify( const struct sigevent *notification ) { - register POSIX_Message_queue_Control *the_mq; - Objects_Locations location; + POSIX_Message_queue_Control *the_mq; + POSIX_Message_queue_Control_fd *the_mq_fd; + Objects_Locations location; - the_mq = _POSIX_Message_queue_Get( mqdes, &location ); + the_mq_fd = _POSIX_Message_queue_Get_fd( mqdes, &location ); switch ( location ) { case OBJECTS_ERROR: rtems_set_errno_and_return_minus_one( EBADF ); @@ -76,6 +77,8 @@ int mq_notify( return POSIX_MP_NOT_IMPLEMENTED(); rtems_set_errno_and_return_minus_one( EINVAL ); case OBJECTS_LOCAL: + the_mq = the_mq_fd->Queue; + if ( notification ) { if ( _CORE_message_queue_Is_notify_enabled( &the_mq->Message_queue ) ) { _Thread_Enable_dispatch(); diff --git a/c/src/exec/posix/src/mqueueopen.c b/c/src/exec/posix/src/mqueueopen.c index 0cad4974f6..f0dfc34f7c 100644 --- a/c/src/exec/posix/src/mqueueopen.c +++ b/c/src/exec/posix/src/mqueueopen.c @@ -45,13 +45,14 @@ mqd_t mq_open( /* struct mq_attr attr */ ) { - va_list arg; - mode_t mode; - struct mq_attr *attr = NULL; - int status; - Objects_Id the_mq_id; - POSIX_Message_queue_Control *the_mq; - Objects_Locations location; + va_list arg; + mode_t mode; + 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; _Thread_Disable_dispatch(); @@ -62,8 +63,15 @@ mqd_t mq_open( va_end(arg); } + the_mq_fd = _POSIX_Message_queue_Allocate_fd(); + if ( !the_mq_fd ) { + _Thread_Enable_dispatch(); + rtems_set_errno_and_return_minus_one( ENFILE ); + } + the_mq_fd->oflag = oflag; + status = _POSIX_Message_queue_Name_to_id( name, &the_mq_id ); - + /* * If the name to id translation worked, then the message queue exists * and we can just return a pointer to the id. Otherwise we may @@ -79,6 +87,7 @@ mqd_t mq_open( */ if ( !( status == ENOENT && (oflag & O_CREAT) ) ) { + _POSIX_Message_queue_Free_fd( the_mq_fd ); _Thread_Enable_dispatch(); rtems_set_errno_and_return_minus_one_cast( status, mqd_t ); } @@ -90,20 +99,22 @@ mqd_t mq_open( */ if ( (oflag & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL) ) { + _POSIX_Message_queue_Free_fd( the_mq_fd ); _Thread_Enable_dispatch(); rtems_set_errno_and_return_minus_one_cast( EEXIST, mqd_t ); } /* - * XXX In this case we need to do an ID->pointer conversion to - * check the mode. This is probably a good place for a subroutine. + * 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; _Thread_Enable_dispatch(); _Thread_Enable_dispatch(); - return (mqd_t)the_mq->Object.id; + return (mqd_t)the_mq_fd->Object.id; } @@ -115,7 +126,6 @@ mqd_t mq_open( status = _POSIX_Message_queue_Create_support( name, TRUE, /* shared across processes */ - oflag, attr, &the_mq ); @@ -124,12 +134,22 @@ mqd_t mq_open( * errno was set by Create_support, so don't set it again. */ - _Thread_Enable_dispatch(); - - if ( status == -1 ) + if ( status == -1 ) { + _Thread_Enable_dispatch(); + _POSIX_Message_queue_Free_fd( the_mq_fd ); return (mqd_t) -1; + } + + the_mq_fd->Queue = the_mq; + _Objects_Open( + &_POSIX_Message_queue_Information_fds, + &the_mq_fd->Object, + NULL + ); - return (mqd_t) the_mq->Object.id; + _Thread_Enable_dispatch(); + + return (mqd_t) the_mq_fd->Object.id; } diff --git a/c/src/exec/posix/src/mqueuerecvsupp.c b/c/src/exec/posix/src/mqueuerecvsupp.c index 8c12a2ef53..11d8fbc50c 100644 --- a/c/src/exec/posix/src/mqueuerecvsupp.c +++ b/c/src/exec/posix/src/mqueuerecvsupp.c @@ -48,11 +48,12 @@ ssize_t _POSIX_Message_queue_Receive_support( Watchdog_Interval timeout ) { - register POSIX_Message_queue_Control *the_mq; - Objects_Locations location; - unsigned32 length_out; + POSIX_Message_queue_Control *the_mq; + POSIX_Message_queue_Control_fd *the_mq_fd; + Objects_Locations location; + unsigned32 length_out; - the_mq = _POSIX_Message_queue_Get( mqdes, &location ); + the_mq_fd = _POSIX_Message_queue_Get_fd( mqdes, &location ); switch ( location ) { case OBJECTS_ERROR: rtems_set_errno_and_return_minus_one( EBADF ); @@ -61,11 +62,13 @@ ssize_t _POSIX_Message_queue_Receive_support( return POSIX_MP_NOT_IMPLEMENTED(); rtems_set_errno_and_return_minus_one( EINVAL ); case OBJECTS_LOCAL: - if ( (the_mq->oflag & O_ACCMODE) == O_WRONLY ) { + if ( (the_mq_fd->oflag & O_ACCMODE) == O_WRONLY ) { _Thread_Enable_dispatch(); rtems_set_errno_and_return_minus_one( EBADF ); } + the_mq = the_mq_fd->Queue; + if ( msg_len < the_mq->Message_queue.maximum_message_size ) { _Thread_Enable_dispatch(); rtems_set_errno_and_return_minus_one( EMSGSIZE ); @@ -83,7 +86,7 @@ ssize_t _POSIX_Message_queue_Receive_support( mqdes, msg_ptr, &length_out, - (the_mq->oflag & O_NONBLOCK) ? FALSE : TRUE, + (the_mq_fd->oflag & O_NONBLOCK) ? FALSE : TRUE, timeout ); diff --git a/c/src/exec/posix/src/mqueuesendsupp.c b/c/src/exec/posix/src/mqueuesendsupp.c index c7e6c50764..b3f249638c 100644 --- a/c/src/exec/posix/src/mqueuesendsupp.c +++ b/c/src/exec/posix/src/mqueuesendsupp.c @@ -46,9 +46,10 @@ int _POSIX_Message_queue_Send_support( Watchdog_Interval timeout ) { - register POSIX_Message_queue_Control *the_mq; - Objects_Locations location; - CORE_message_queue_Status msg_status; + POSIX_Message_queue_Control *the_mq; + POSIX_Message_queue_Control_fd *the_mq_fd; + Objects_Locations location; + CORE_message_queue_Status msg_status; /* * Validate the priority. @@ -58,8 +59,7 @@ int _POSIX_Message_queue_Send_support( if ( msg_prio > MQ_PRIO_MAX ) rtems_set_errno_and_return_minus_one( EINVAL ); - the_mq = _POSIX_Message_queue_Get( mqdes, &location ); - + the_mq_fd = _POSIX_Message_queue_Get_fd( mqdes, &location ); switch ( location ) { case OBJECTS_ERROR: rtems_set_errno_and_return_minus_one( EBADF ); @@ -70,11 +70,13 @@ int _POSIX_Message_queue_Send_support( rtems_set_errno_and_return_minus_one( EINVAL ); case OBJECTS_LOCAL: - if ( (the_mq->oflag & O_ACCMODE) == O_RDONLY ) { + if ( (the_mq_fd->oflag & O_ACCMODE) == O_RDONLY ) { _Thread_Enable_dispatch(); rtems_set_errno_and_return_minus_one( EBADF ); } + the_mq = the_mq_fd->Queue; + msg_status = _CORE_message_queue_Submit( &the_mq->Message_queue, (void *) msg_ptr, @@ -86,7 +88,7 @@ int _POSIX_Message_queue_Send_support( NULL, #endif _POSIX_Message_queue_Priority_to_core( msg_prio ), - (the_mq->oflag & O_NONBLOCK) ? FALSE : TRUE, + (the_mq_fd->oflag & O_NONBLOCK) ? FALSE : TRUE, timeout /* no timeout */ ); diff --git a/c/src/exec/posix/src/mqueuesetattr.c b/c/src/exec/posix/src/mqueuesetattr.c index 142b7ad15e..623bf32744 100644 --- a/c/src/exec/posix/src/mqueuesetattr.c +++ b/c/src/exec/posix/src/mqueuesetattr.c @@ -43,15 +43,14 @@ int mq_setattr( struct mq_attr *omqstat ) { - register POSIX_Message_queue_Control *the_mq; - CORE_message_queue_Control *the_core_mq; - Objects_Locations location; - CORE_message_queue_Attributes *the_mq_attr; + POSIX_Message_queue_Control_fd *the_mq_fd; + CORE_message_queue_Control *the_core_mq; + Objects_Locations location; if ( !mqstat ) rtems_set_errno_and_return_minus_one( EINVAL ); - the_mq = _POSIX_Message_queue_Get( mqdes, &location ); + the_mq_fd = _POSIX_Message_queue_Get_fd( mqdes, &location ); switch ( location ) { case OBJECTS_ERROR: rtems_set_errno_and_return_minus_one( EBADF ); @@ -61,38 +60,20 @@ int mq_setattr( rtems_set_errno_and_return_minus_one( EINVAL ); case OBJECTS_LOCAL: - the_core_mq = &the_mq->Message_queue; + the_core_mq = &the_mq_fd->Queue->Message_queue; /* * Return the old values. */ - /* XXX this is the same stuff as is in mq_getattr... and probably */ - /* XXX should be in an inlined private routine */ - if ( omqstat ) { - omqstat->mq_flags = the_mq->oflag; + omqstat->mq_flags = the_mq_fd->oflag; omqstat->mq_msgsize = the_core_mq->maximum_message_size; omqstat->mq_maxmsg = the_core_mq->maximum_pending_messages; omqstat->mq_curmsgs = the_core_mq->number_of_pending_messages; } - - /* - * If blocking was in effect and is not now, then there - * may be threads blocked on this message queue which need - * to be unblocked to make the state of the message queue - * consistent for future use. - */ - the_mq_attr = &the_core_mq->Attributes; - - if ( !(the_mq->oflag & O_NONBLOCK) && /* were blocking */ - (mqstat->mq_flags & O_NONBLOCK) ) { /* and now are not */ - _CORE_message_queue_Flush_waiting_threads( the_core_mq ); - } - - the_mq->oflag = mqstat->mq_flags; - + the_mq_fd->oflag = mqstat->mq_flags; _Thread_Enable_dispatch(); return 0; } -- cgit v1.2.3