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/rtems/messageimpl.h> |
---|
22 | #include <rtems/rtems/status.h> |
---|
23 | #include <rtems/rtems/attrimpl.h> |
---|
24 | #include <rtems/rtems/options.h> |
---|
25 | #include <rtems/rtems/support.h> |
---|
26 | #include <rtems/score/sysstate.h> |
---|
27 | #include <rtems/score/chain.h> |
---|
28 | #include <rtems/score/isr.h> |
---|
29 | #include <rtems/score/coremsgimpl.h> |
---|
30 | #include <rtems/score/thread.h> |
---|
31 | #include <rtems/score/wkspace.h> |
---|
32 | #include <rtems/sysinit.h> |
---|
33 | |
---|
34 | rtems_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_Disciplines discipline; |
---|
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 | the_message_queue = _Message_queue_Allocate(); |
---|
85 | |
---|
86 | if ( !the_message_queue ) { |
---|
87 | _Objects_Allocator_unlock(); |
---|
88 | return RTEMS_TOO_MANY; |
---|
89 | } |
---|
90 | |
---|
91 | #if defined(RTEMS_MULTIPROCESSING) |
---|
92 | if ( is_global && |
---|
93 | !( _Objects_MP_Allocate_and_open( &_Message_queue_Information, |
---|
94 | name, the_message_queue->Object.id, false ) ) ) { |
---|
95 | _Message_queue_Free( the_message_queue ); |
---|
96 | _Objects_Allocator_unlock(); |
---|
97 | return RTEMS_TOO_MANY; |
---|
98 | } |
---|
99 | #endif |
---|
100 | |
---|
101 | the_message_queue->attribute_set = attribute_set; |
---|
102 | |
---|
103 | if (_Attributes_Is_priority( attribute_set ) ) |
---|
104 | discipline = CORE_MESSAGE_QUEUE_DISCIPLINES_PRIORITY; |
---|
105 | else |
---|
106 | discipline = CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO; |
---|
107 | |
---|
108 | if ( ! _CORE_message_queue_Initialize( |
---|
109 | &the_message_queue->message_queue, |
---|
110 | discipline, |
---|
111 | count, |
---|
112 | max_message_size |
---|
113 | ) ) { |
---|
114 | #if defined(RTEMS_MULTIPROCESSING) |
---|
115 | if ( is_global ) |
---|
116 | _Objects_MP_Close( |
---|
117 | &_Message_queue_Information, the_message_queue->Object.id); |
---|
118 | #endif |
---|
119 | |
---|
120 | _Message_queue_Free( the_message_queue ); |
---|
121 | _Objects_Allocator_unlock(); |
---|
122 | return RTEMS_UNSATISFIED; |
---|
123 | } |
---|
124 | |
---|
125 | _Objects_Open( |
---|
126 | &_Message_queue_Information, |
---|
127 | &the_message_queue->Object, |
---|
128 | (Objects_Name) name |
---|
129 | ); |
---|
130 | |
---|
131 | *id = the_message_queue->Object.id; |
---|
132 | |
---|
133 | #if defined(RTEMS_MULTIPROCESSING) |
---|
134 | if ( is_global ) |
---|
135 | _Message_queue_MP_Send_process_packet( |
---|
136 | MESSAGE_QUEUE_MP_ANNOUNCE_CREATE, |
---|
137 | the_message_queue->Object.id, |
---|
138 | name, |
---|
139 | 0 |
---|
140 | ); |
---|
141 | #endif |
---|
142 | |
---|
143 | _Objects_Allocator_unlock(); |
---|
144 | return RTEMS_SUCCESSFUL; |
---|
145 | } |
---|
146 | |
---|
147 | static void _Message_queue_Manager_initialization( void ) |
---|
148 | { |
---|
149 | _Objects_Initialize_information( &_Message_queue_Information); |
---|
150 | } |
---|
151 | |
---|
152 | RTEMS_SYSINIT_ITEM( |
---|
153 | _Message_queue_Manager_initialization, |
---|
154 | RTEMS_SYSINIT_CLASSIC_MESSAGE_QUEUE, |
---|
155 | RTEMS_SYSINIT_ORDER_MIDDLE |
---|
156 | ); |
---|