source: rtems/cpukit/rtems/src/msgqcreate.c @ c18e0ba

4.115
Last change on this file since c18e0ba was c18e0ba, checked in by Alex Ivanov <alexivanov97@…>, on 12/04/12 at 22:59:11

rtems misc: Clean up Doxygen GCI Task #4

http://www.google-melange.com/gci/task/view/google/gci2012/7950205

  • Property mode set to 100644
File size: 3.8 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief RTEMS Create Message Queue
5 *  @ingroup ClassicMessageQueue
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-1999.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.com/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <rtems/system.h>
22#include <rtems/score/sysstate.h>
23#include <rtems/score/chain.h>
24#include <rtems/score/isr.h>
25#include <rtems/score/coremsg.h>
26#include <rtems/score/object.h>
27#include <rtems/score/states.h>
28#include <rtems/score/thread.h>
29#include <rtems/score/wkspace.h>
30#if defined(RTEMS_MULTIPROCESSING)
31#include <rtems/score/mpci.h>
32#endif
33#include <rtems/rtems/status.h>
34#include <rtems/rtems/attr.h>
35#include <rtems/rtems/message.h>
36#include <rtems/rtems/options.h>
37#include <rtems/rtems/support.h>
38
39rtems_status_code rtems_message_queue_create(
40  rtems_name       name,
41  uint32_t         count,
42  size_t           max_message_size,
43  rtems_attribute  attribute_set,
44  rtems_id        *id
45)
46{
47  register Message_queue_Control *the_message_queue;
48  CORE_message_queue_Attributes   the_msgq_attributes;
49#if defined(RTEMS_MULTIPROCESSING)
50  bool                            is_global;
51  size_t                          max_packet_payload_size;
52#endif
53
54  if ( !rtems_is_name_valid( name ) )
55    return RTEMS_INVALID_NAME;
56
57  if ( !id )
58    return RTEMS_INVALID_ADDRESS;
59
60#if defined(RTEMS_MULTIPROCESSING)
61  if ( (is_global = _Attributes_Is_global( attribute_set ) ) &&
62       !_System_state_Is_multiprocessing )
63    return RTEMS_MP_NOT_CONFIGURED;
64#endif
65
66  if ( count == 0 )
67      return RTEMS_INVALID_NUMBER;
68
69  if ( max_message_size == 0 )
70      return RTEMS_INVALID_SIZE;
71
72#if defined(RTEMS_MULTIPROCESSING)
73#if 1
74  /*
75   * I am not 100% sure this should be an error.
76   * It seems reasonable to create a que with a large max size,
77   * and then just send smaller msgs from remote (or all) nodes.
78   */
79
80  max_packet_payload_size = _MPCI_table->maximum_packet_size
81    - MESSAGE_QUEUE_MP_PACKET_SIZE;
82  if ( is_global && max_packet_payload_size < max_message_size )
83    return RTEMS_INVALID_SIZE;
84#endif
85#endif
86
87  _Thread_Disable_dispatch();              /* protects object pointer */
88
89  the_message_queue = _Message_queue_Allocate();
90
91  if ( !the_message_queue ) {
92    _Thread_Enable_dispatch();
93    return RTEMS_TOO_MANY;
94  }
95
96#if defined(RTEMS_MULTIPROCESSING)
97  if ( is_global &&
98    !( _Objects_MP_Allocate_and_open( &_Message_queue_Information,
99                              name, the_message_queue->Object.id, false ) ) ) {
100    _Message_queue_Free( the_message_queue );
101    _Thread_Enable_dispatch();
102    return RTEMS_TOO_MANY;
103  }
104#endif
105
106  the_message_queue->attribute_set = attribute_set;
107
108  if (_Attributes_Is_priority( attribute_set ) )
109    the_msgq_attributes.discipline = CORE_MESSAGE_QUEUE_DISCIPLINES_PRIORITY;
110  else
111    the_msgq_attributes.discipline = CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO;
112
113  if ( ! _CORE_message_queue_Initialize(
114           &the_message_queue->message_queue,
115           &the_msgq_attributes,
116           count,
117           max_message_size
118         ) ) {
119#if defined(RTEMS_MULTIPROCESSING)
120    if ( is_global )
121        _Objects_MP_Close(
122          &_Message_queue_Information, the_message_queue->Object.id);
123#endif
124
125    _Message_queue_Free( the_message_queue );
126    _Thread_Enable_dispatch();
127    return RTEMS_UNSATISFIED;
128  }
129
130  _Objects_Open(
131    &_Message_queue_Information,
132    &the_message_queue->Object,
133    (Objects_Name) name
134  );
135
136  *id = the_message_queue->Object.id;
137
138#if defined(RTEMS_MULTIPROCESSING)
139  if ( is_global )
140    _Message_queue_MP_Send_process_packet(
141      MESSAGE_QUEUE_MP_ANNOUNCE_CREATE,
142      the_message_queue->Object.id,
143      name,
144      0
145    );
146#endif
147
148  _Thread_Enable_dispatch();
149  return RTEMS_SUCCESSFUL;
150}
Note: See TracBrowser for help on using the repository browser.