From c8982e5f6a4857444676165deab1e08dc91a6847 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Tue, 26 Apr 2016 21:20:31 +0200 Subject: posix: Simplify message queues The mq_open() function returns a descriptor to a POSIX message queue object identified by a name. This is similar to sem_open(). In contrast to the POSIX semaphore the POSIX message queues use a separate object for the descriptor. This extra object is superfluous, since the object identifier can be used directly for this purpose, just like for the semaphores. Update #2702. Update #2555. --- cpukit/posix/src/mqueuenotify.c | 78 +++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 49 deletions(-) (limited to 'cpukit/posix/src/mqueuenotify.c') diff --git a/cpukit/posix/src/mqueuenotify.c b/cpukit/posix/src/mqueuenotify.c index d31a8e662d..adcfdcb8f2 100644 --- a/cpukit/posix/src/mqueuenotify.c +++ b/cpukit/posix/src/mqueuenotify.c @@ -18,25 +18,9 @@ #include "config.h" #endif -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include #include -/* - * _POSIX_Message_queue_Notify_handler - * - */ +#include static void _POSIX_Message_queue_Notify_handler( CORE_message_queue_Control *the_message_queue, @@ -64,45 +48,41 @@ int mq_notify( const struct sigevent *notification ) { - POSIX_Message_queue_Control *the_mq; - POSIX_Message_queue_Control_fd *the_mq_fd; - Objects_Locations location; - - the_mq_fd = _POSIX_Message_queue_Get_fd( mqdes, &location ); - switch ( location ) { - - case OBJECTS_LOCAL: - the_mq = the_mq_fd->Queue; - - if ( notification ) { - if ( _CORE_message_queue_Is_notify_enabled( &the_mq->Message_queue ) ) { - _Objects_Put( &the_mq_fd->Object ); - rtems_set_errno_and_return_minus_one( EBUSY ); - } + POSIX_Message_queue_Control *the_mq; + ISR_lock_Context lock_context; - _CORE_message_queue_Set_notify( &the_mq->Message_queue, NULL ); + the_mq = _POSIX_Message_queue_Get( mqdes, &lock_context ); - the_mq->notification = *notification; + if ( the_mq == NULL ) { + rtems_set_errno_and_return_minus_one( EBADF ); + } - _CORE_message_queue_Set_notify( - &the_mq->Message_queue, - _POSIX_Message_queue_Notify_handler - ); - } else { + _CORE_message_queue_Acquire_critical( + &the_mq->Message_queue, + &lock_context + ); - _CORE_message_queue_Set_notify( &the_mq->Message_queue, NULL ); + if ( the_mq->open_count == 0 ) { + _CORE_message_queue_Release( &the_mq->Message_queue, &lock_context ); + rtems_set_errno_and_return_minus_one( EBADF ); + } - } + if ( notification != NULL ) { + if ( _CORE_message_queue_Is_notify_enabled( &the_mq->Message_queue ) ) { + _CORE_message_queue_Release( &the_mq->Message_queue, &lock_context ); + rtems_set_errno_and_return_minus_one( EBUSY ); + } - _Objects_Put( &the_mq_fd->Object ); - return 0; + the_mq->notification = *notification; -#if defined(RTEMS_MULTIPROCESSING) - case OBJECTS_REMOTE: -#endif - case OBJECTS_ERROR: - break; + _CORE_message_queue_Set_notify( + &the_mq->Message_queue, + _POSIX_Message_queue_Notify_handler + ); + } else { + _CORE_message_queue_Set_notify( &the_mq->Message_queue, NULL ); } - rtems_set_errno_and_return_minus_one( EBADF ); + _CORE_message_queue_Release( &the_mq->Message_queue, &lock_context ); + return 0; } -- cgit v1.2.3