Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:21

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup POSIXAPI
0007  *
0008  * @brief Message Queue Attributes
0009  */
0010 
0011 /*
0012  *  NOTE:  The structure of the routines is identical to that of POSIX
0013  *         Message_queues to leave the option of having unnamed message
0014  *         queues at a future date.  They are currently not part of the
0015  *         POSIX standard but unnamed message_queues are.  This is also
0016  *         the reason for the apparently unnecessary tracking of
0017  *         the process_shared attribute.  [In addition to the fact that
0018  *         it would be trivial to add pshared to the mq_attr structure
0019  *         and have process private message queues.]
0020  *
0021  *         This code ignores the O_RDONLY/O_WRONLY/O_RDWR flag at open
0022  *         time.
0023  *
0024  *  COPYRIGHT (c) 1989-2011.
0025  *  On-Line Applications Research Corporation (OAR).
0026  *
0027  * Redistribution and use in source and binary forms, with or without
0028  * modification, are permitted provided that the following conditions
0029  * are met:
0030  * 1. Redistributions of source code must retain the above copyright
0031  *    notice, this list of conditions and the following disclaimer.
0032  * 2. Redistributions in binary form must reproduce the above copyright
0033  *    notice, this list of conditions and the following disclaimer in the
0034  *    documentation and/or other materials provided with the distribution.
0035  *
0036  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0037  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0038  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0039  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0040  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0041  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0042  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0043  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0044  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0045  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0046  * POSSIBILITY OF SUCH DAMAGE.
0047  */
0048 
0049 #ifdef HAVE_CONFIG_H
0050 #include "config.h"
0051 #endif
0052 
0053 #include <rtems/posix/mqueueimpl.h>
0054 
0055 /*
0056  *  15.2.8 Get Message Queue Attributes, P1003.1b-1993, p. 283
0057  */
0058 
0059 int mq_getattr(
0060   mqd_t           mqdes,
0061   struct mq_attr *mqstat
0062 )
0063 {
0064   POSIX_Message_queue_Control *the_mq;
0065   Thread_queue_Context         queue_context;
0066 
0067   if ( mqstat == NULL ) {
0068     rtems_set_errno_and_return_minus_one( EINVAL );
0069   }
0070 
0071   the_mq = _POSIX_Message_queue_Get( mqdes, &queue_context );
0072 
0073   if ( the_mq == NULL ) {
0074     rtems_set_errno_and_return_minus_one( EBADF );
0075   }
0076 
0077   _CORE_message_queue_Acquire_critical(
0078     &the_mq->Message_queue,
0079     &queue_context
0080   );
0081 
0082   if ( the_mq->open_count == 0 ) {
0083     _CORE_message_queue_Release( &the_mq->Message_queue, &queue_context );
0084     rtems_set_errno_and_return_minus_one( EBADF );
0085   }
0086 
0087   /*
0088    *  Return the old values.
0089    */
0090   mqstat->mq_flags   = the_mq->oflag;
0091   mqstat->mq_msgsize = the_mq->Message_queue.maximum_message_size;
0092   mqstat->mq_maxmsg  = the_mq->Message_queue.maximum_pending_messages;
0093   mqstat->mq_curmsgs = the_mq->Message_queue.number_of_pending_messages;
0094 
0095   _CORE_message_queue_Release( &the_mq->Message_queue, &queue_context );
0096   return 0;
0097 }