source: rtems/cpukit/rtems/src/msgqcreate.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: 3.7 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief RTEMS Create Message Queue
5 *  @ingroup ClassicMessageQueue
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2014.
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.org/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/thread.h>
27#include <rtems/score/wkspace.h>
28#include <rtems/rtems/status.h>
29#include <rtems/rtems/attrimpl.h>
30#include <rtems/rtems/messageimpl.h>
31#include <rtems/rtems/options.h>
32#include <rtems/rtems/support.h>
33
34rtems_status_code rtems_message_queue_create(
35  rtems_name       name,
36  uint32_t         count,
37  size_t           max_message_size,
38  rtems_attribute  attribute_set,
39  rtems_id        *id
40)
41{
42  Message_queue_Control          *the_message_queue;
43  CORE_message_queue_Attributes   the_msgq_attributes;
44#if defined(RTEMS_MULTIPROCESSING)
45  bool                            is_global;
46#endif
47
48  if ( !rtems_is_name_valid( name ) )
49    return RTEMS_INVALID_NAME;
50
51  if ( !id )
52    return RTEMS_INVALID_ADDRESS;
53
54#if defined(RTEMS_MULTIPROCESSING)
55  if ( (is_global = _Attributes_Is_global( attribute_set ) ) &&
56       !_System_state_Is_multiprocessing )
57    return RTEMS_MP_NOT_CONFIGURED;
58#endif
59
60  if ( count == 0 )
61      return RTEMS_INVALID_NUMBER;
62
63  if ( max_message_size == 0 )
64      return RTEMS_INVALID_SIZE;
65
66#if defined(RTEMS_MULTIPROCESSING)
67#if 1
68  /*
69   * I am not 100% sure this should be an error.
70   * It seems reasonable to create a que with a large max size,
71   * and then just send smaller msgs from remote (or all) nodes.
72   */
73  if ( is_global ) {
74    size_t max_packet_payload_size = _MPCI_table->maximum_packet_size
75      - MESSAGE_QUEUE_MP_PACKET_SIZE;
76
77    if ( max_message_size > max_packet_payload_size ) {
78      return RTEMS_INVALID_SIZE;
79    }
80  }
81#endif
82#endif
83
84  _Thread_Disable_dispatch();              /* protects object pointer */
85
86  the_message_queue = _Message_queue_Allocate();
87
88  if ( !the_message_queue ) {
89    _Thread_Enable_dispatch();
90    return RTEMS_TOO_MANY;
91  }
92
93#if defined(RTEMS_MULTIPROCESSING)
94  if ( is_global &&
95    !( _Objects_MP_Allocate_and_open( &_Message_queue_Information,
96                              name, the_message_queue->Object.id, false ) ) ) {
97    _Message_queue_Free( the_message_queue );
98    _Thread_Enable_dispatch();
99    return RTEMS_TOO_MANY;
100  }
101#endif
102
103  the_message_queue->attribute_set = attribute_set;
104
105  if (_Attributes_Is_priority( attribute_set ) )
106    the_msgq_attributes.discipline = CORE_MESSAGE_QUEUE_DISCIPLINES_PRIORITY;
107  else
108    the_msgq_attributes.discipline = CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO;
109
110  if ( ! _CORE_message_queue_Initialize(
111           &the_message_queue->message_queue,
112           &the_msgq_attributes,
113           count,
114           max_message_size
115         ) ) {
116#if defined(RTEMS_MULTIPROCESSING)
117    if ( is_global )
118        _Objects_MP_Close(
119          &_Message_queue_Information, the_message_queue->Object.id);
120#endif
121
122    _Message_queue_Free( the_message_queue );
123    _Thread_Enable_dispatch();
124    return RTEMS_UNSATISFIED;
125  }
126
127  _Objects_Open(
128    &_Message_queue_Information,
129    &the_message_queue->Object,
130    (Objects_Name) name
131  );
132
133  *id = the_message_queue->Object.id;
134
135#if defined(RTEMS_MULTIPROCESSING)
136  if ( is_global )
137    _Message_queue_MP_Send_process_packet(
138      MESSAGE_QUEUE_MP_ANNOUNCE_CREATE,
139      the_message_queue->Object.id,
140      name,
141      0
142    );
143#endif
144
145  _Thread_Enable_dispatch();
146  return RTEMS_SUCCESSFUL;
147}
Note: See TracBrowser for help on using the repository browser.