RTEMS
msgqconstruct.c
Go to the documentation of this file.
1 
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 #ifdef HAVE_CONFIG_H
18 #include "config.h"
19 #endif
20 
22 #include <rtems/rtems/attrimpl.h>
23 #include <rtems/rtems/support.h>
25 #include <rtems/sysinit.h>
26 
27 static void *_Message_queue_Get_buffers(
28  CORE_message_queue_Control *the_message_queue,
29  size_t size,
30  const void *arg
31 )
32 {
33  const rtems_message_queue_config *config;
34 
35  config = arg;
36 
37  if ( config->storage_size != size ) {
38  return NULL;
39  }
40 
41  the_message_queue->free_message_buffers = config->storage_free;
42  return config->storage_area;
43 }
44 
46  const rtems_message_queue_config *config,
47  rtems_id *id
48 )
49 {
50  return _Message_queue_Create( config, id, _Message_queue_Get_buffers );
51 }
52 
54  const rtems_message_queue_config *config,
55  rtems_id *id,
57 )
58 {
59  Message_queue_Control *the_message_queue;
61  Status_Control status;
62 #if defined(RTEMS_MULTIPROCESSING)
63  bool is_global;
64 #endif
65 
66  if ( !rtems_is_name_valid( config->name ) ) {
67  return RTEMS_INVALID_NAME;
68  }
69 
70  if ( id == NULL ) {
71  return RTEMS_INVALID_ADDRESS;
72  }
73 
74  if ( config->maximum_pending_messages == 0 ) {
75  return RTEMS_INVALID_NUMBER;
76  }
77 
78  if ( config->maximum_message_size == 0 ) {
79  return RTEMS_INVALID_SIZE;
80  }
81 
82 #if defined(RTEMS_MULTIPROCESSING)
83  if ( _System_state_Is_multiprocessing ) {
84  is_global = _Attributes_Is_global( config->attributes );
85  } else {
86  is_global = false;
87  }
88 
89 #if 1
90  /*
91  * I am not 100% sure this should be an error.
92  * It seems reasonable to create a que with a large max size,
93  * and then just send smaller msgs from remote (or all) nodes.
94  */
95  if ( is_global ) {
96  size_t max_packet_payload_size = _MPCI_table->maximum_packet_size
97  - MESSAGE_QUEUE_MP_PACKET_SIZE;
98 
99  if ( config->maximum_message_size > max_packet_payload_size ) {
100  return RTEMS_INVALID_SIZE;
101  }
102  }
103 #endif
104 #endif
105 
106  the_message_queue = _Message_queue_Allocate();
107 
108  if ( !the_message_queue ) {
110  return RTEMS_TOO_MANY;
111  }
112 
113 #if defined(RTEMS_MULTIPROCESSING)
114  if (
115  is_global
116  && !_Objects_MP_Allocate_and_open(
118  config->name,
119  the_message_queue->Object.id,
120  false
121  )
122  ) {
123  _Message_queue_Free( the_message_queue );
125  return RTEMS_TOO_MANY;
126  }
127 
128  the_message_queue->is_global = is_global;
129 #endif
130 
131  if ( _Attributes_Is_priority( config->attributes ) ) {
133  } else {
135  }
136 
138  &the_message_queue->message_queue,
139  discipline,
140  config->maximum_pending_messages,
141  config->maximum_message_size,
142  allocate_buffers,
143  config
144  );
145 
146  if ( status != STATUS_SUCCESSFUL ) {
147 #if defined(RTEMS_MULTIPROCESSING)
148  if ( is_global )
149  _Objects_MP_Close(
150  &_Message_queue_Information, the_message_queue->Object.id);
151 #endif
152 
153  _Message_queue_Free( the_message_queue );
155  return STATUS_GET_CLASSIC( status );
156  }
157 
160  &the_message_queue->Object,
161  (Objects_Name) config->name
162  );
163 
164  *id = the_message_queue->Object.id;
165 
166 #if defined(RTEMS_MULTIPROCESSING)
167  if ( is_global )
168  _Message_queue_MP_Send_process_packet(
169  MESSAGE_QUEUE_MP_ANNOUNCE_CREATE,
170  the_message_queue->Object.id,
171  config->name,
172  0
173  );
174 #endif
175 
177  return RTEMS_SUCCESSFUL;
178 }
179 
180 static void _Message_queue_Manager_initialization( void )
181 {
183 }
184 
185 RTEMS_SYSINIT_ITEM(
186  _Message_queue_Manager_initialization,
187  RTEMS_SYSINIT_CLASSIC_MESSAGE_QUEUE,
188  RTEMS_SYSINIT_ORDER_MIDDLE
189 );
This status code indicates you have attempted to create too many instances of a particular object cla...
Definition: status.h:112
static __inline__ void _Objects_Allocator_unlock(void)
Unlocks the object allocator mutex.
Definition: objectimpl.h:846
This header file defines support services of the API.
RTEMS_INLINE_ROUTINE bool _Attributes_Is_priority(rtems_attribute attribute_set)
Checks if the priority attribute is enabled in the attribute_set.
Definition: attrimpl.h:119
Classic Message Queue Manager Implementation.
Inlined Routines in the Core Message Handler.
void _Objects_Initialize_information(Objects_Information *information)
Initializes the specified objects information.
static __inline__ void _Message_queue_Free(Message_queue_Control *the_message_queue)
Deallocates a message queue control block into the inactive chain of free message queue control block...
Definition: messageimpl.h:78
void(* storage_free)(void *)
This member defines the optional handler to free the message buffer storage area. ...
Definition: message.h:128
static bool rtems_is_name_valid(rtems_status_code name)
Returns true, if the specified object name is valid, otherwise returns false.
Definition: support.h:126
Objects_Control Object
Definition: messagedata.h:40
void *(* CORE_message_queue_Allocate_buffers)(CORE_message_queue_Control *the_message_queue, size_t size, const void *arg)
This handler shall allocate the message buffer storage area for a message queue.
Definition: coremsgimpl.h:89
This status code indicates that a specified number was invalid.
Definition: status.h:138
void(* free_message_buffers)(void *)
This member contains the optional message buffer storage area free handler.
Definition: coremsg.h:135
rtems_status_code _Message_queue_Create(const rtems_message_queue_config *config, rtems_id *id, CORE_message_queue_Allocate_buffers allocate_buffers)
Creates a message queue.
Definition: msgqconstruct.c:53
rtems_name name
This member defines the name of the message queue.
Definition: message.h:91
Objects_Information _Message_queue_Information
The Classic Message Queue objects information.
Definition: msg.c:47
This status code indicates successful completion.
Definition: status.h:86
static __inline__ void _Objects_Open(Objects_Information *information, Objects_Control *the_object, Objects_Name name)
Places the_object control pointer and object name in the Local Pointer and Local Name Tables...
Definition: objectimpl.h:750
rtems_status_code
This enumeration provides status codes for directives of the Classic API.
Definition: status.h:82
This structure defines the configuration of a message queue constructed by rtems_message_queue_constr...
Definition: message.h:87
CORE_message_queue_Control message_queue
Definition: messagedata.h:42
void * storage_area
This member shall point to the message buffer storage area begin.
Definition: message.h:112
This status code indicates that a specified address was invalid.
Definition: status.h:133
CORE_message_queue_Disciplines
The possible blocking disciplines for a message queue.
Definition: coremsg.h:69
Status_Control _CORE_message_queue_Initialize(CORE_message_queue_Control *the_message_queue, CORE_message_queue_Disciplines discipline, uint32_t maximum_pending_messages, size_t maximum_message_size, CORE_message_queue_Allocate_buffers allocate_buffers, const void *arg)
Initializes a message queue.
Definition: coremsg.c:33
Classic Attributes Implementation.
Objects_Id rtems_id
Values of this type identify an RTEMS object.
Definition: types.h:99
Control block used to manage each message queue.
Definition: coremsg.h:96
rtems_status_code rtems_message_queue_construct(const rtems_message_queue_config *config, rtems_id *id)
Constructs a message queue from the specified the message queue configuration.
Definition: msgqconstruct.c:45
This status code indicates that an object name was invalid.
Definition: status.h:101
rtems_attribute attributes
This member defines the attributes of the message queue.
Definition: message.h:133
size_t storage_size
This member defines size of the message buffer storage area in bytes.
Definition: message.h:117
This status code indicates that a specified size was invalid.
Definition: status.h:128
size_t maximum_message_size
This member defines the maximum message size supported by the message queue.
Definition: message.h:103
uint32_t maximum_pending_messages
This member defines the maximum number of pending messages supported by the message queue...
Definition: message.h:97
Objects_Id id
Definition: objectdata.h:43