1 | /* |
---|
2 | * Multiprocessing Support for the Message Queue Manager |
---|
3 | * |
---|
4 | * |
---|
5 | * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994. |
---|
6 | * On-Line Applications Research Corporation (OAR). |
---|
7 | * All rights assigned to U.S. Government, 1994. |
---|
8 | * |
---|
9 | * This material may be reproduced by or for the U.S. Government pursuant |
---|
10 | * to the copyright license under the clause at DFARS 252.227-7013. This |
---|
11 | * notice must appear in all copies of this file and its derivatives. |
---|
12 | * |
---|
13 | * $Id$ |
---|
14 | */ |
---|
15 | |
---|
16 | #include <rtems/system.h> |
---|
17 | #include <rtems/rtems/status.h> |
---|
18 | #include <rtems/rtems/message.h> |
---|
19 | #include <rtems/core/mpci.h> |
---|
20 | #include <rtems/rtems/msgmp.h> |
---|
21 | #include <rtems/core/object.h> |
---|
22 | #include <rtems/rtems/options.h> |
---|
23 | #include <rtems/core/thread.h> |
---|
24 | #include <rtems/core/watchdog.h> |
---|
25 | #include <rtems/rtems/support.h> |
---|
26 | |
---|
27 | /*PAGE |
---|
28 | * |
---|
29 | * _Message_queue_MP_Send_process_packet |
---|
30 | * |
---|
31 | */ |
---|
32 | |
---|
33 | void _Message_queue_MP_Send_process_packet ( |
---|
34 | Message_queue_MP_Remote_operations operation, |
---|
35 | Objects_Id message_queue_id, |
---|
36 | rtems_name name, |
---|
37 | Objects_Id proxy_id |
---|
38 | ) |
---|
39 | { |
---|
40 | Message_queue_MP_Packet *the_packet; |
---|
41 | unsigned32 node; |
---|
42 | |
---|
43 | switch ( operation ) { |
---|
44 | |
---|
45 | case MESSAGE_QUEUE_MP_ANNOUNCE_CREATE: |
---|
46 | case MESSAGE_QUEUE_MP_ANNOUNCE_DELETE: |
---|
47 | case MESSAGE_QUEUE_MP_EXTRACT_PROXY: |
---|
48 | |
---|
49 | the_packet = _Message_queue_MP_Get_packet(); |
---|
50 | the_packet->Prefix.the_class = MP_PACKET_MESSAGE_QUEUE; |
---|
51 | the_packet->Prefix.length = sizeof ( Message_queue_MP_Packet ); |
---|
52 | the_packet->Prefix.to_convert = sizeof ( Message_queue_MP_Packet ); |
---|
53 | the_packet->operation = operation; |
---|
54 | the_packet->Prefix.id = message_queue_id; |
---|
55 | the_packet->name = name; |
---|
56 | the_packet->proxy_id = proxy_id; |
---|
57 | |
---|
58 | if ( operation == MESSAGE_QUEUE_MP_EXTRACT_PROXY ) |
---|
59 | node = rtems_get_node( message_queue_id ); |
---|
60 | else |
---|
61 | node = MPCI_ALL_NODES; |
---|
62 | |
---|
63 | _MPCI_Send_process_packet( node, &the_packet->Prefix ); |
---|
64 | break; |
---|
65 | |
---|
66 | case MESSAGE_QUEUE_MP_RECEIVE_REQUEST: |
---|
67 | case MESSAGE_QUEUE_MP_RECEIVE_RESPONSE: |
---|
68 | case MESSAGE_QUEUE_MP_SEND_REQUEST: |
---|
69 | case MESSAGE_QUEUE_MP_SEND_RESPONSE: |
---|
70 | case MESSAGE_QUEUE_MP_URGENT_REQUEST: |
---|
71 | case MESSAGE_QUEUE_MP_URGENT_RESPONSE: |
---|
72 | case MESSAGE_QUEUE_MP_BROADCAST_REQUEST: |
---|
73 | case MESSAGE_QUEUE_MP_BROADCAST_RESPONSE: |
---|
74 | case MESSAGE_QUEUE_MP_FLUSH_REQUEST: |
---|
75 | case MESSAGE_QUEUE_MP_FLUSH_RESPONSE: |
---|
76 | break; |
---|
77 | |
---|
78 | } |
---|
79 | } |
---|
80 | |
---|
81 | /*PAGE |
---|
82 | * |
---|
83 | * _Message_queue_MP_Send_request_packet |
---|
84 | * |
---|
85 | */ |
---|
86 | |
---|
87 | rtems_status_code _Message_queue_MP_Send_request_packet ( |
---|
88 | Message_queue_MP_Remote_operations operation, |
---|
89 | Objects_Id message_queue_id, |
---|
90 | void *buffer, |
---|
91 | unsigned32 *size_p, |
---|
92 | rtems_option option_set, |
---|
93 | rtems_interval timeout |
---|
94 | ) |
---|
95 | { |
---|
96 | Message_queue_MP_Packet *the_packet; |
---|
97 | |
---|
98 | switch ( operation ) { |
---|
99 | |
---|
100 | case MESSAGE_QUEUE_MP_SEND_REQUEST: |
---|
101 | case MESSAGE_QUEUE_MP_URGENT_REQUEST: |
---|
102 | case MESSAGE_QUEUE_MP_BROADCAST_REQUEST: |
---|
103 | case MESSAGE_QUEUE_MP_FLUSH_REQUEST: |
---|
104 | |
---|
105 | the_packet = _Message_queue_MP_Get_packet(); |
---|
106 | the_packet->Prefix.the_class = MP_PACKET_MESSAGE_QUEUE; |
---|
107 | the_packet->Prefix.length = sizeof(Message_queue_MP_Packet); |
---|
108 | if ( size_p ) |
---|
109 | the_packet->Prefix.length += *size_p; |
---|
110 | the_packet->Prefix.to_convert = sizeof(Message_queue_MP_Packet); |
---|
111 | |
---|
112 | /* |
---|
113 | * make sure message is not too big for our MPCI driver |
---|
114 | * We have to check it here instead of waiting for MPCI because |
---|
115 | * we are about to slam in the payload |
---|
116 | */ |
---|
117 | |
---|
118 | if (the_packet->Prefix.length > _MPCI_table->maximum_packet_size) { |
---|
119 | _Thread_Enable_dispatch(); |
---|
120 | return RTEMS_INVALID_SIZE; |
---|
121 | } |
---|
122 | |
---|
123 | if ( ! _Options_Is_no_wait(option_set)) |
---|
124 | the_packet->Prefix.timeout = timeout; |
---|
125 | |
---|
126 | the_packet->operation = operation; |
---|
127 | the_packet->Prefix.id = message_queue_id; |
---|
128 | the_packet->option_set = option_set; |
---|
129 | |
---|
130 | /* |
---|
131 | * Copy the data into place if needed |
---|
132 | */ |
---|
133 | |
---|
134 | if (buffer) { |
---|
135 | the_packet->Buffer.size = *size_p; |
---|
136 | _Message_queue_Copy_buffer(buffer, |
---|
137 | the_packet->Buffer.buffer, |
---|
138 | *size_p); |
---|
139 | } |
---|
140 | |
---|
141 | return _MPCI_Send_request_packet(rtems_get_node(message_queue_id), |
---|
142 | &the_packet->Prefix, |
---|
143 | STATES_WAITING_FOR_MESSAGE); |
---|
144 | break; |
---|
145 | |
---|
146 | case MESSAGE_QUEUE_MP_RECEIVE_REQUEST: |
---|
147 | |
---|
148 | the_packet = _Message_queue_MP_Get_packet(); |
---|
149 | the_packet->Prefix.the_class = MP_PACKET_MESSAGE_QUEUE; |
---|
150 | the_packet->Prefix.length = sizeof(Message_queue_MP_Packet); |
---|
151 | the_packet->Prefix.to_convert = sizeof(Message_queue_MP_Packet); |
---|
152 | |
---|
153 | if ( ! _Options_Is_no_wait(option_set)) |
---|
154 | the_packet->Prefix.timeout = timeout; |
---|
155 | |
---|
156 | the_packet->operation = MESSAGE_QUEUE_MP_RECEIVE_REQUEST; |
---|
157 | the_packet->Prefix.id = message_queue_id; |
---|
158 | the_packet->option_set = option_set; |
---|
159 | the_packet->size = 0; /* just in case of an error */ |
---|
160 | |
---|
161 | _Thread_Executing->Wait.return_argument = (unsigned32 *)buffer; |
---|
162 | _Thread_Executing->Wait.return_argument_1 = size_p; |
---|
163 | |
---|
164 | return _MPCI_Send_request_packet(rtems_get_node(message_queue_id), |
---|
165 | &the_packet->Prefix, |
---|
166 | STATES_WAITING_FOR_MESSAGE); |
---|
167 | break; |
---|
168 | |
---|
169 | case MESSAGE_QUEUE_MP_ANNOUNCE_CREATE: |
---|
170 | case MESSAGE_QUEUE_MP_ANNOUNCE_DELETE: |
---|
171 | case MESSAGE_QUEUE_MP_EXTRACT_PROXY: |
---|
172 | case MESSAGE_QUEUE_MP_RECEIVE_RESPONSE: |
---|
173 | case MESSAGE_QUEUE_MP_SEND_RESPONSE: |
---|
174 | case MESSAGE_QUEUE_MP_URGENT_RESPONSE: |
---|
175 | case MESSAGE_QUEUE_MP_BROADCAST_RESPONSE: |
---|
176 | case MESSAGE_QUEUE_MP_FLUSH_RESPONSE: |
---|
177 | break; |
---|
178 | } |
---|
179 | |
---|
180 | return RTEMS_SUCCESSFUL; |
---|
181 | } |
---|
182 | |
---|
183 | /*PAGE |
---|
184 | * |
---|
185 | * _Message_queue_MP_Send_response_packet |
---|
186 | * |
---|
187 | */ |
---|
188 | |
---|
189 | void _Message_queue_MP_Send_response_packet ( |
---|
190 | Message_queue_MP_Remote_operations operation, |
---|
191 | Objects_Id message_queue_id, |
---|
192 | Thread_Control *the_thread |
---|
193 | ) |
---|
194 | { |
---|
195 | Message_queue_MP_Packet *the_packet; |
---|
196 | |
---|
197 | switch ( operation ) { |
---|
198 | |
---|
199 | case MESSAGE_QUEUE_MP_RECEIVE_RESPONSE: |
---|
200 | case MESSAGE_QUEUE_MP_SEND_RESPONSE: |
---|
201 | case MESSAGE_QUEUE_MP_URGENT_RESPONSE: |
---|
202 | case MESSAGE_QUEUE_MP_BROADCAST_RESPONSE: |
---|
203 | case MESSAGE_QUEUE_MP_FLUSH_RESPONSE: |
---|
204 | |
---|
205 | the_packet = ( Message_queue_MP_Packet *) the_thread->receive_packet; |
---|
206 | |
---|
207 | /* |
---|
208 | * The packet being returned already contains the class, length, and |
---|
209 | * to_convert fields, therefore they are not set in this routine. |
---|
210 | * |
---|
211 | * Exception: MESSAGE_QUEUE_MP_RECEIVE_RESPONSE needs payload length |
---|
212 | * added to 'length' |
---|
213 | */ |
---|
214 | the_packet->operation = operation; |
---|
215 | the_packet->Prefix.id = the_packet->Prefix.source_tid; |
---|
216 | |
---|
217 | if (operation == MESSAGE_QUEUE_MP_RECEIVE_RESPONSE) |
---|
218 | the_packet->Prefix.length += the_packet->size; |
---|
219 | |
---|
220 | _MPCI_Send_response_packet( |
---|
221 | rtems_get_node( the_packet->Prefix.source_tid ), |
---|
222 | &the_packet->Prefix |
---|
223 | ); |
---|
224 | break; |
---|
225 | |
---|
226 | case MESSAGE_QUEUE_MP_ANNOUNCE_CREATE: |
---|
227 | case MESSAGE_QUEUE_MP_ANNOUNCE_DELETE: |
---|
228 | case MESSAGE_QUEUE_MP_EXTRACT_PROXY: |
---|
229 | case MESSAGE_QUEUE_MP_RECEIVE_REQUEST: |
---|
230 | case MESSAGE_QUEUE_MP_SEND_REQUEST: |
---|
231 | case MESSAGE_QUEUE_MP_URGENT_REQUEST: |
---|
232 | case MESSAGE_QUEUE_MP_BROADCAST_REQUEST: |
---|
233 | case MESSAGE_QUEUE_MP_FLUSH_REQUEST: |
---|
234 | break; |
---|
235 | |
---|
236 | } |
---|
237 | } |
---|
238 | |
---|
239 | /*PAGE |
---|
240 | * |
---|
241 | * |
---|
242 | * _Message_queue_MP_Process_packet |
---|
243 | * |
---|
244 | */ |
---|
245 | |
---|
246 | void _Message_queue_MP_Process_packet ( |
---|
247 | rtems_packet_prefix *the_packet_prefix |
---|
248 | ) |
---|
249 | { |
---|
250 | Message_queue_MP_Packet *the_packet; |
---|
251 | Thread_Control *the_thread; |
---|
252 | boolean ignored; |
---|
253 | |
---|
254 | the_packet = (Message_queue_MP_Packet *) the_packet_prefix; |
---|
255 | |
---|
256 | switch ( the_packet->operation ) { |
---|
257 | |
---|
258 | case MESSAGE_QUEUE_MP_ANNOUNCE_CREATE: |
---|
259 | |
---|
260 | ignored = _Objects_MP_Allocate_and_open( |
---|
261 | &_Message_queue_Information, |
---|
262 | the_packet->name, |
---|
263 | the_packet->Prefix.id, |
---|
264 | TRUE |
---|
265 | ); |
---|
266 | |
---|
267 | _MPCI_Return_packet( the_packet_prefix ); |
---|
268 | break; |
---|
269 | |
---|
270 | case MESSAGE_QUEUE_MP_ANNOUNCE_DELETE: |
---|
271 | |
---|
272 | _Objects_MP_Close( &_Message_queue_Information, the_packet->Prefix.id ); |
---|
273 | |
---|
274 | _MPCI_Return_packet( the_packet_prefix ); |
---|
275 | break; |
---|
276 | |
---|
277 | case MESSAGE_QUEUE_MP_EXTRACT_PROXY: |
---|
278 | |
---|
279 | the_thread = _Thread_MP_Find_proxy( the_packet->proxy_id ); |
---|
280 | |
---|
281 | if ( ! _Thread_Is_null( the_thread ) ) |
---|
282 | _Thread_queue_Extract( the_thread->Wait.queue, the_thread ); |
---|
283 | |
---|
284 | _MPCI_Return_packet( the_packet_prefix ); |
---|
285 | break; |
---|
286 | |
---|
287 | case MESSAGE_QUEUE_MP_RECEIVE_REQUEST: |
---|
288 | |
---|
289 | the_packet->Prefix.return_code = rtems_message_queue_receive( |
---|
290 | the_packet->Prefix.id, |
---|
291 | the_packet->Buffer.buffer, |
---|
292 | &the_packet->size, |
---|
293 | the_packet->option_set, |
---|
294 | the_packet->Prefix.timeout |
---|
295 | ); |
---|
296 | |
---|
297 | if ( ! _Thread_Is_proxy_blocking( the_packet->Prefix.return_code ) ) |
---|
298 | _Message_queue_MP_Send_response_packet( |
---|
299 | MESSAGE_QUEUE_MP_RECEIVE_RESPONSE, |
---|
300 | the_packet->Prefix.id, |
---|
301 | _Thread_Executing |
---|
302 | ); |
---|
303 | break; |
---|
304 | |
---|
305 | case MESSAGE_QUEUE_MP_RECEIVE_RESPONSE: |
---|
306 | |
---|
307 | the_thread = _MPCI_Process_response( the_packet_prefix ); |
---|
308 | |
---|
309 | if (the_packet->Prefix.return_code == RTEMS_SUCCESSFUL) { |
---|
310 | *(rtems_unsigned32 *)the_thread->Wait.return_argument_1 = |
---|
311 | the_packet->size; |
---|
312 | |
---|
313 | _Message_queue_Copy_buffer( |
---|
314 | the_packet->Buffer.buffer, |
---|
315 | the_thread->Wait.return_argument, |
---|
316 | the_packet->size |
---|
317 | ); |
---|
318 | } |
---|
319 | |
---|
320 | _MPCI_Return_packet( the_packet_prefix ); |
---|
321 | break; |
---|
322 | |
---|
323 | case MESSAGE_QUEUE_MP_SEND_REQUEST: |
---|
324 | |
---|
325 | the_packet->Prefix.return_code = rtems_message_queue_send( |
---|
326 | the_packet->Prefix.id, |
---|
327 | the_packet->Buffer.buffer, |
---|
328 | the_packet->Buffer.size |
---|
329 | ); |
---|
330 | |
---|
331 | _Message_queue_MP_Send_response_packet( |
---|
332 | MESSAGE_QUEUE_MP_SEND_RESPONSE, |
---|
333 | the_packet->Prefix.id, |
---|
334 | _Thread_Executing |
---|
335 | ); |
---|
336 | break; |
---|
337 | |
---|
338 | case MESSAGE_QUEUE_MP_SEND_RESPONSE: |
---|
339 | case MESSAGE_QUEUE_MP_URGENT_RESPONSE: |
---|
340 | |
---|
341 | the_thread = _MPCI_Process_response( the_packet_prefix ); |
---|
342 | |
---|
343 | _MPCI_Return_packet( the_packet_prefix ); |
---|
344 | break; |
---|
345 | |
---|
346 | case MESSAGE_QUEUE_MP_URGENT_REQUEST: |
---|
347 | |
---|
348 | the_packet->Prefix.return_code = rtems_message_queue_urgent( |
---|
349 | the_packet->Prefix.id, |
---|
350 | the_packet->Buffer.buffer, |
---|
351 | the_packet->Buffer.size |
---|
352 | ); |
---|
353 | |
---|
354 | _Message_queue_MP_Send_response_packet( |
---|
355 | MESSAGE_QUEUE_MP_URGENT_RESPONSE, |
---|
356 | the_packet->Prefix.id, |
---|
357 | _Thread_Executing |
---|
358 | ); |
---|
359 | break; |
---|
360 | |
---|
361 | case MESSAGE_QUEUE_MP_BROADCAST_REQUEST: |
---|
362 | |
---|
363 | the_packet->Prefix.return_code = rtems_message_queue_broadcast( |
---|
364 | the_packet->Prefix.id, |
---|
365 | the_packet->Buffer.buffer, |
---|
366 | the_packet->Buffer.size, |
---|
367 | &the_packet->count |
---|
368 | ); |
---|
369 | |
---|
370 | _Message_queue_MP_Send_response_packet( |
---|
371 | MESSAGE_QUEUE_MP_BROADCAST_RESPONSE, |
---|
372 | the_packet->Prefix.id, |
---|
373 | _Thread_Executing |
---|
374 | ); |
---|
375 | break; |
---|
376 | |
---|
377 | case MESSAGE_QUEUE_MP_BROADCAST_RESPONSE: |
---|
378 | case MESSAGE_QUEUE_MP_FLUSH_RESPONSE: |
---|
379 | |
---|
380 | the_thread = _MPCI_Process_response( the_packet_prefix ); |
---|
381 | |
---|
382 | *(unsigned32 *)the_thread->Wait.return_argument = the_packet->count; |
---|
383 | |
---|
384 | _MPCI_Return_packet( the_packet_prefix ); |
---|
385 | break; |
---|
386 | |
---|
387 | case MESSAGE_QUEUE_MP_FLUSH_REQUEST: |
---|
388 | |
---|
389 | the_packet->Prefix.return_code = rtems_message_queue_flush( |
---|
390 | the_packet->Prefix.id, |
---|
391 | &the_packet->count |
---|
392 | ); |
---|
393 | |
---|
394 | _Message_queue_MP_Send_response_packet( |
---|
395 | MESSAGE_QUEUE_MP_FLUSH_RESPONSE, |
---|
396 | the_packet->Prefix.id, |
---|
397 | _Thread_Executing |
---|
398 | ); |
---|
399 | break; |
---|
400 | |
---|
401 | } |
---|
402 | } |
---|
403 | |
---|
404 | /*PAGE |
---|
405 | * |
---|
406 | * _Message_queue_MP_Send_object_was_deleted |
---|
407 | * |
---|
408 | */ |
---|
409 | |
---|
410 | void _Message_queue_MP_Send_object_was_deleted ( |
---|
411 | Thread_Control *the_proxy |
---|
412 | ) |
---|
413 | { |
---|
414 | the_proxy->receive_packet->return_code = RTEMS_OBJECT_WAS_DELETED; |
---|
415 | |
---|
416 | _Message_queue_MP_Send_response_packet( |
---|
417 | MESSAGE_QUEUE_MP_RECEIVE_RESPONSE, |
---|
418 | the_proxy->Wait.id, |
---|
419 | the_proxy |
---|
420 | ); |
---|
421 | } |
---|
422 | |
---|
423 | /*PAGE |
---|
424 | * |
---|
425 | * _Message_queue_MP_Send_extract_proxy |
---|
426 | * |
---|
427 | */ |
---|
428 | |
---|
429 | void _Message_queue_MP_Send_extract_proxy ( |
---|
430 | Thread_Control *the_thread |
---|
431 | ) |
---|
432 | { |
---|
433 | _Message_queue_MP_Send_process_packet( |
---|
434 | MESSAGE_QUEUE_MP_EXTRACT_PROXY, |
---|
435 | the_thread->Wait.id, |
---|
436 | (rtems_name) 0, |
---|
437 | the_thread->Object.id |
---|
438 | ); |
---|
439 | } |
---|
440 | |
---|
441 | /*PAGE |
---|
442 | * |
---|
443 | * _Message_queue_MP_Get_packet |
---|
444 | * |
---|
445 | */ |
---|
446 | |
---|
447 | Message_queue_MP_Packet *_Message_queue_MP_Get_packet ( void ) |
---|
448 | { |
---|
449 | return ( (Message_queue_MP_Packet *) _MPCI_Get_packet() ); |
---|
450 | } |
---|
451 | |
---|
452 | /* end of file */ |
---|