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

4.115
Last change on this file since b5d514f was b5d514f, checked in by Sebastian Huber <sebastian.huber@…>, on 07/18/13 at 13:35:23

score: Create message queue implementation header

Move implementation specific parts of coremsg.h and coremsg.inl into new
header file coremsgimpl.h. The coremsg.h contains now only the
application visible API.

  • 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/coremsgimpl.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/messageimpl.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#endif
52
53  if ( !rtems_is_name_valid( name ) )
54    return RTEMS_INVALID_NAME;
55
56  if ( !id )
57    return RTEMS_INVALID_ADDRESS;
58
59#if defined(RTEMS_MULTIPROCESSING)
60  if ( (is_global = _Attributes_Is_global( attribute_set ) ) &&
61       !_System_state_Is_multiprocessing )
62    return RTEMS_MP_NOT_CONFIGURED;
63#endif
64
65  if ( count == 0 )
66      return RTEMS_INVALID_NUMBER;
67
68  if ( max_message_size == 0 )
69      return RTEMS_INVALID_SIZE;
70
71#if defined(RTEMS_MULTIPROCESSING)
72#if 1
73  /*
74   * I am not 100% sure this should be an error.
75   * It seems reasonable to create a que with a large max size,
76   * and then just send smaller msgs from remote (or all) nodes.
77   */
78  if ( is_global ) {
79    size_t max_packet_payload_size = _MPCI_table->maximum_packet_size
80      - MESSAGE_QUEUE_MP_PACKET_SIZE;
81
82    if ( max_message_size > max_packet_payload_size ) {
83      return RTEMS_INVALID_SIZE;
84    }
85  }
86#endif
87#endif
88
89  _Thread_Disable_dispatch();              /* protects object pointer */
90
91  the_message_queue = _Message_queue_Allocate();
92
93  if ( !the_message_queue ) {
94    _Thread_Enable_dispatch();
95    return RTEMS_TOO_MANY;
96  }
97
98#if defined(RTEMS_MULTIPROCESSING)
99  if ( is_global &&
100    !( _Objects_MP_Allocate_and_open( &_Message_queue_Information,
101                              name, the_message_queue->Object.id, false ) ) ) {
102    _Message_queue_Free( the_message_queue );
103    _Thread_Enable_dispatch();
104    return RTEMS_TOO_MANY;
105  }
106#endif
107
108  the_message_queue->attribute_set = attribute_set;
109
110  if (_Attributes_Is_priority( attribute_set ) )
111    the_msgq_attributes.discipline = CORE_MESSAGE_QUEUE_DISCIPLINES_PRIORITY;
112  else
113    the_msgq_attributes.discipline = CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO;
114
115  if ( ! _CORE_message_queue_Initialize(
116           &the_message_queue->message_queue,
117           &the_msgq_attributes,
118           count,
119           max_message_size
120         ) ) {
121#if defined(RTEMS_MULTIPROCESSING)
122    if ( is_global )
123        _Objects_MP_Close(
124          &_Message_queue_Information, the_message_queue->Object.id);
125#endif
126
127    _Message_queue_Free( the_message_queue );
128    _Thread_Enable_dispatch();
129    return RTEMS_UNSATISFIED;
130  }
131
132  _Objects_Open(
133    &_Message_queue_Information,
134    &the_message_queue->Object,
135    (Objects_Name) name
136  );
137
138  *id = the_message_queue->Object.id;
139
140#if defined(RTEMS_MULTIPROCESSING)
141  if ( is_global )
142    _Message_queue_MP_Send_process_packet(
143      MESSAGE_QUEUE_MP_ANNOUNCE_CREATE,
144      the_message_queue->Object.id,
145      name,
146      0
147    );
148#endif
149
150  _Thread_Enable_dispatch();
151  return RTEMS_SUCCESSFUL;
152}
Note: See TracBrowser for help on using the repository browser.