diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-04-26 21:20:31 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-05-02 07:46:15 +0200 |
commit | c8982e5f6a4857444676165deab1e08dc91a6847 (patch) | |
tree | 9862d54650522b55afac8a4e1b84ab078a69dff5 /cpukit/posix/src/mqueueclose.c | |
parent | rtems: Avoid Giant lock for message queues (diff) | |
download | rtems-c8982e5f6a4857444676165deab1e08dc91a6847.tar.bz2 |
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.
Diffstat (limited to 'cpukit/posix/src/mqueueclose.c')
-rw-r--r-- | cpukit/posix/src/mqueueclose.c | 62 |
1 files changed, 20 insertions, 42 deletions
diff --git a/cpukit/posix/src/mqueueclose.c b/cpukit/posix/src/mqueueclose.c index 2864e95f3c..28a7d164d9 100644 --- a/cpukit/posix/src/mqueueclose.c +++ b/cpukit/posix/src/mqueueclose.c @@ -30,17 +30,6 @@ #include "config.h" #endif -#include <stdarg.h> - -#include <pthread.h> -#include <limits.h> -#include <errno.h> -#include <fcntl.h> -#include <mqueue.h> - -#include <rtems/system.h> -#include <rtems/score/watchdog.h> -#include <rtems/seterr.h> #include <rtems/posix/mqueueimpl.h> /* @@ -52,42 +41,31 @@ int mq_close( mqd_t mqdes ) { - POSIX_Message_queue_Control *the_mq; - POSIX_Message_queue_Control_fd *the_mq_fd; - Objects_Locations location; + POSIX_Message_queue_Control *the_mq; + ISR_lock_Context lock_context; _Objects_Allocator_lock(); - the_mq_fd = _POSIX_Message_queue_Get_fd( mqdes, &location ); - if ( location == OBJECTS_LOCAL ) { - /* 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 ); + the_mq = _POSIX_Message_queue_Get( mqdes, &lock_context ); - /* - * Now close this file descriptor. - */ + if ( the_mq == NULL ) { + _Objects_Allocator_unlock(); + rtems_set_errno_and_return_minus_one( EBADF ); + } - _Objects_Close( - &_POSIX_Message_queue_Information_fds, &the_mq_fd->Object ); - _POSIX_Message_queue_Free_fd( the_mq_fd ); + _CORE_message_queue_Acquire_critical( + &the_mq->Message_queue, + &lock_context + ); - _Objects_Put( &the_mq_fd->Object ); - _Objects_Allocator_unlock(); - return 0; - } + if ( the_mq->open_count == 0 ) { + _CORE_message_queue_Release( &the_mq->Message_queue, &lock_context ); + _Objects_Allocator_unlock(); + rtems_set_errno_and_return_minus_one( EBADF ); + } - _Objects_Allocator_unlock(); + the_mq->open_count -= 1; + _POSIX_Message_queue_Delete( the_mq, &lock_context ); - /* - * OBJECTS_REMOTE: - * OBJECTS_ERROR: - */ - rtems_set_errno_and_return_minus_one( EBADF ); + _Objects_Allocator_unlock(); + return 0; } |