source: rtems/cpukit/posix/src/mqueueclose.c @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 2.3 KB
Line 
1/**
2 * @file
3 *
4 * @brief Function closes the Message Queue
5 * @ingroup POSIXAPI
6 */
7
8/*
9 *  NOTE:  The structure of the routines is identical to that of POSIX
10 *         Message_queues to leave the option of having unnamed message
11 *         queues at a future date.  They are currently not part of the
12 *         POSIX standard but unnamed message_queues are.  This is also
13 *         the reason for the apparently unnecessary tracking of
14 *         the process_shared attribute.  [In addition to the fact that
15 *         it would be trivial to add pshared to the mq_attr structure
16 *         and have process private message queues.]
17 *
18 *         This code ignores the O_RDONLY/O_WRONLY/O_RDWR flag at open
19 *         time.
20 *
21 *  COPYRIGHT (c) 1989-2008.
22 *  On-Line Applications Research Corporation (OAR).
23 *
24 *  The license and distribution terms for this file may be
25 *  found in the file LICENSE in this distribution or at
26 *  http://www.rtems.org/license/LICENSE.
27 */
28
29#if HAVE_CONFIG_H
30#include "config.h"
31#endif
32
33#include <stdarg.h>
34
35#include <pthread.h>
36#include <limits.h>
37#include <errno.h>
38#include <fcntl.h>
39#include <mqueue.h>
40
41#include <rtems/system.h>
42#include <rtems/score/watchdog.h>
43#include <rtems/seterr.h>
44#include <rtems/posix/mqueueimpl.h>
45#include <rtems/posix/time.h>
46
47/*
48 *
49 *  15.2.2 Close a Message Queue, P1003.1b-1993, p. 275
50 */
51
52int mq_close(
53  mqd_t  mqdes
54)
55{
56  POSIX_Message_queue_Control    *the_mq;
57  POSIX_Message_queue_Control_fd *the_mq_fd;
58  Objects_Locations               location;
59
60  the_mq_fd = _POSIX_Message_queue_Get_fd( mqdes, &location );
61  if ( location == OBJECTS_LOCAL ) {
62      /* OBJECTS_LOCAL:
63       *
64       *  First update the actual message queue to reflect this descriptor
65       *  being disassociated.  This may result in the queue being really
66       *  deleted.
67       */
68
69      the_mq = the_mq_fd->Queue;
70      the_mq->open_count -= 1;
71      _POSIX_Message_queue_Delete( the_mq );
72
73      /*
74       *  Now close this file descriptor.
75       */
76
77      _Objects_Close(
78        &_POSIX_Message_queue_Information_fds, &the_mq_fd->Object );
79      _POSIX_Message_queue_Free_fd( the_mq_fd );
80
81      _Objects_Put( &the_mq_fd->Object );
82      return 0;
83   }
84
85   /*
86    *  OBJECTS_REMOTE:
87    *  OBJECTS_ERROR:
88    */
89   rtems_set_errno_and_return_minus_one( EBADF );
90}
Note: See TracBrowser for help on using the repository browser.