source: rtems/cpukit/posix/src/mqueueclose.c @ 0e16fa45

5
Last change on this file since 0e16fa45 was 631b3c8, checked in by Sebastian Huber <sebastian.huber@…>, on 05/23/16 at 09:40:18

score: Move thread queue MP callout to context

Drop the multiprocessing (MP) dependent callout parameter from the
thread queue extract, dequeue, flush and unblock methods. Merge this
parameter with the lock context into new structure Thread_queue_Context.
This helps to gets rid of the conditionally compiled method call
helpers.

  • Property mode set to 100644
File size: 1.8 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 <rtems/posix/mqueueimpl.h>
34
35/*
36 *
37 *  15.2.2 Close a Message Queue, P1003.1b-1993, p. 275
38 */
39
40int mq_close(
41  mqd_t  mqdes
42)
43{
44  POSIX_Message_queue_Control *the_mq;
45  Thread_queue_Context         queue_context;
46
47  _Objects_Allocator_lock();
48  the_mq = _POSIX_Message_queue_Get( mqdes, &queue_context );
49
50  if ( the_mq == NULL ) {
51    _Objects_Allocator_unlock();
52    rtems_set_errno_and_return_minus_one( EBADF );
53  }
54
55  _CORE_message_queue_Acquire_critical(
56    &the_mq->Message_queue,
57    &queue_context
58  );
59
60  if ( the_mq->open_count == 0 ) {
61    _CORE_message_queue_Release( &the_mq->Message_queue, &queue_context );
62    _Objects_Allocator_unlock();
63    rtems_set_errno_and_return_minus_one( EBADF );
64  }
65
66  the_mq->open_count -= 1;
67  _POSIX_Message_queue_Delete( the_mq, &queue_context );
68
69  _Objects_Allocator_unlock();
70  return 0;
71}
Note: See TracBrowser for help on using the repository browser.