1 | /* |
---|
2 | * Message Queue Manager |
---|
3 | * |
---|
4 | * |
---|
5 | * COPYRIGHT (c) 1989-1998. |
---|
6 | * On-Line Applications Research Corporation (OAR). |
---|
7 | * Copyright assigned to U.S. Government, 1994. |
---|
8 | * |
---|
9 | * The license and distribution terms for this file may be |
---|
10 | * found in the file LICENSE in this distribution or at |
---|
11 | * http://www.OARcorp.com/rtems/license.html. |
---|
12 | * |
---|
13 | * $Id$ |
---|
14 | */ |
---|
15 | |
---|
16 | #include <rtems/system.h> |
---|
17 | #include <rtems/score/sysstate.h> |
---|
18 | #include <rtems/score/chain.h> |
---|
19 | #include <rtems/score/isr.h> |
---|
20 | #include <rtems/score/coremsg.h> |
---|
21 | #include <rtems/score/object.h> |
---|
22 | #include <rtems/score/states.h> |
---|
23 | #include <rtems/score/thread.h> |
---|
24 | #include <rtems/score/wkspace.h> |
---|
25 | #if defined(RTEMS_MULTIPROCESSING) |
---|
26 | #include <rtems/score/mpci.h> |
---|
27 | #endif |
---|
28 | #include <rtems/rtems/status.h> |
---|
29 | #include <rtems/rtems/attr.h> |
---|
30 | #include <rtems/rtems/message.h> |
---|
31 | #include <rtems/rtems/options.h> |
---|
32 | #include <rtems/rtems/support.h> |
---|
33 | |
---|
34 | /*PAGE |
---|
35 | * |
---|
36 | * _Message_queue_Manager_initialization |
---|
37 | * |
---|
38 | * This routine initializes all message queue manager related |
---|
39 | * data structures. |
---|
40 | * |
---|
41 | * Input parameters: |
---|
42 | * maximum_message_queues - number of message queues to initialize |
---|
43 | * |
---|
44 | * Output parameters: NONE |
---|
45 | */ |
---|
46 | |
---|
47 | void _Message_queue_Manager_initialization( |
---|
48 | unsigned32 maximum_message_queues |
---|
49 | ) |
---|
50 | { |
---|
51 | _Objects_Initialize_information( |
---|
52 | &_Message_queue_Information, |
---|
53 | OBJECTS_RTEMS_MESSAGE_QUEUES, |
---|
54 | TRUE, |
---|
55 | maximum_message_queues, |
---|
56 | sizeof( Message_queue_Control ), |
---|
57 | FALSE, |
---|
58 | RTEMS_MAXIMUM_NAME_LENGTH, |
---|
59 | FALSE |
---|
60 | ); |
---|
61 | |
---|
62 | /* |
---|
63 | * Register the MP Process Packet routine. |
---|
64 | */ |
---|
65 | |
---|
66 | #if defined(RTEMS_MULTIPROCESSING) |
---|
67 | _MPCI_Register_packet_processor( |
---|
68 | MP_PACKET_MESSAGE_QUEUE, |
---|
69 | _Message_queue_MP_Process_packet |
---|
70 | ); |
---|
71 | #endif |
---|
72 | |
---|
73 | } |
---|
74 | |
---|
75 | /*PAGE |
---|
76 | * |
---|
77 | * _Message_queue_Allocate |
---|
78 | * |
---|
79 | * Allocate a message queue and the space for its messages |
---|
80 | * |
---|
81 | * Input parameters: |
---|
82 | * the_message_queue - the message queue to allocate message buffers |
---|
83 | * count - maximum message and reserved buffer count |
---|
84 | * max_message_size - maximum size of each message |
---|
85 | * |
---|
86 | * Output parameters: |
---|
87 | * the_message_queue - set if successful, NULL otherwise |
---|
88 | */ |
---|
89 | |
---|
90 | Message_queue_Control *_Message_queue_Allocate ( |
---|
91 | unsigned32 count, |
---|
92 | unsigned32 max_message_size |
---|
93 | ) |
---|
94 | { |
---|
95 | return |
---|
96 | (Message_queue_Control *)_Objects_Allocate(&_Message_queue_Information); |
---|
97 | |
---|
98 | } |
---|
99 | |
---|
100 | /*PAGE |
---|
101 | * |
---|
102 | * rtems_message_queue_create |
---|
103 | * |
---|
104 | * This directive creates a message queue by allocating and initializing |
---|
105 | * a message queue data structure. |
---|
106 | * |
---|
107 | * Input parameters: |
---|
108 | * name - user defined queue name |
---|
109 | * count - maximum message and reserved buffer count |
---|
110 | * max_message_size - maximum size of each message |
---|
111 | * attribute_set - process method |
---|
112 | * id - pointer to queue |
---|
113 | * |
---|
114 | * Output parameters: |
---|
115 | * id - queue id |
---|
116 | * RTEMS_SUCCESSFUL - if successful |
---|
117 | * error code - if unsuccessful |
---|
118 | */ |
---|
119 | |
---|
120 | rtems_status_code rtems_message_queue_create( |
---|
121 | rtems_name name, |
---|
122 | unsigned32 count, |
---|
123 | unsigned32 max_message_size, |
---|
124 | rtems_attribute attribute_set, |
---|
125 | Objects_Id *id |
---|
126 | ) |
---|
127 | { |
---|
128 | register Message_queue_Control *the_message_queue; |
---|
129 | CORE_message_queue_Attributes the_message_queue_attributes; |
---|
130 | void *handler; |
---|
131 | #if defined(RTEMS_MULTIPROCESSING) |
---|
132 | boolean is_global; |
---|
133 | #endif |
---|
134 | |
---|
135 | if ( !rtems_is_name_valid( name ) ) |
---|
136 | return RTEMS_INVALID_NAME; |
---|
137 | |
---|
138 | #if defined(RTEMS_MULTIPROCESSING) |
---|
139 | if ( (is_global = _Attributes_Is_global( attribute_set ) ) && |
---|
140 | !_System_state_Is_multiprocessing ) |
---|
141 | return RTEMS_MP_NOT_CONFIGURED; |
---|
142 | #endif |
---|
143 | |
---|
144 | if (count == 0) |
---|
145 | return RTEMS_INVALID_NUMBER; |
---|
146 | |
---|
147 | if (max_message_size == 0) |
---|
148 | return RTEMS_INVALID_SIZE; |
---|
149 | |
---|
150 | #if defined(RTEMS_MULTIPROCESSING) |
---|
151 | #if 1 |
---|
152 | /* |
---|
153 | * I am not 100% sure this should be an error. |
---|
154 | * It seems reasonable to create a que with a large max size, |
---|
155 | * and then just send smaller msgs from remote (or all) nodes. |
---|
156 | */ |
---|
157 | |
---|
158 | if ( is_global && (_MPCI_table->maximum_packet_size < max_message_size) ) |
---|
159 | return RTEMS_INVALID_SIZE; |
---|
160 | #endif |
---|
161 | #endif |
---|
162 | |
---|
163 | _Thread_Disable_dispatch(); /* protects object pointer */ |
---|
164 | |
---|
165 | the_message_queue = _Message_queue_Allocate( count, max_message_size ); |
---|
166 | |
---|
167 | if ( !the_message_queue ) { |
---|
168 | _Thread_Enable_dispatch(); |
---|
169 | return RTEMS_TOO_MANY; |
---|
170 | } |
---|
171 | |
---|
172 | #if defined(RTEMS_MULTIPROCESSING) |
---|
173 | if ( is_global && |
---|
174 | !( _Objects_MP_Allocate_and_open( &_Message_queue_Information, |
---|
175 | name, the_message_queue->Object.id, FALSE ) ) ) { |
---|
176 | _Message_queue_Free( the_message_queue ); |
---|
177 | _Thread_Enable_dispatch(); |
---|
178 | return RTEMS_TOO_MANY; |
---|
179 | } |
---|
180 | #endif |
---|
181 | |
---|
182 | the_message_queue->attribute_set = attribute_set; |
---|
183 | |
---|
184 | if (_Attributes_Is_priority( attribute_set ) ) |
---|
185 | the_message_queue_attributes.discipline = |
---|
186 | CORE_MESSAGE_QUEUE_DISCIPLINES_PRIORITY; |
---|
187 | else |
---|
188 | the_message_queue_attributes.discipline = |
---|
189 | CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO; |
---|
190 | |
---|
191 | handler = NULL; |
---|
192 | #if defined(RTEMS_MULTIPROCESSING) |
---|
193 | handler = _Message_queue_MP_Send_extract_proxy; |
---|
194 | #endif |
---|
195 | |
---|
196 | if ( ! _CORE_message_queue_Initialize( |
---|
197 | &the_message_queue->message_queue, |
---|
198 | OBJECTS_RTEMS_MESSAGE_QUEUES, |
---|
199 | &the_message_queue_attributes, |
---|
200 | count, |
---|
201 | max_message_size, |
---|
202 | handler ) ) { |
---|
203 | #if defined(RTEMS_MULTIPROCESSING) |
---|
204 | if ( is_global ) |
---|
205 | _Objects_MP_Close( |
---|
206 | &_Message_queue_Information, the_message_queue->Object.id); |
---|
207 | #endif |
---|
208 | |
---|
209 | _Message_queue_Free( the_message_queue ); |
---|
210 | _Thread_Enable_dispatch(); |
---|
211 | return RTEMS_TOO_MANY; |
---|
212 | } |
---|
213 | |
---|
214 | _Objects_Open( |
---|
215 | &_Message_queue_Information, |
---|
216 | &the_message_queue->Object, |
---|
217 | &name |
---|
218 | ); |
---|
219 | |
---|
220 | *id = the_message_queue->Object.id; |
---|
221 | |
---|
222 | #if defined(RTEMS_MULTIPROCESSING) |
---|
223 | if ( is_global ) |
---|
224 | _Message_queue_MP_Send_process_packet( |
---|
225 | MESSAGE_QUEUE_MP_ANNOUNCE_CREATE, |
---|
226 | the_message_queue->Object.id, |
---|
227 | name, |
---|
228 | 0 |
---|
229 | ); |
---|
230 | #endif |
---|
231 | |
---|
232 | _Thread_Enable_dispatch(); |
---|
233 | return RTEMS_SUCCESSFUL; |
---|
234 | } |
---|
235 | |
---|
236 | /*PAGE |
---|
237 | * |
---|
238 | * rtems_message_queue_ident |
---|
239 | * |
---|
240 | * This directive returns the system ID associated with |
---|
241 | * the message queue name. |
---|
242 | * |
---|
243 | * Input parameters: |
---|
244 | * name - user defined message queue name |
---|
245 | * node - node(s) to be searched |
---|
246 | * id - pointer to message queue id |
---|
247 | * |
---|
248 | * Output parameters: |
---|
249 | * *id - message queue id |
---|
250 | * RTEMS_SUCCESSFUL - if successful |
---|
251 | * error code - if unsuccessful |
---|
252 | */ |
---|
253 | |
---|
254 | rtems_status_code rtems_message_queue_ident( |
---|
255 | rtems_name name, |
---|
256 | unsigned32 node, |
---|
257 | Objects_Id *id |
---|
258 | ) |
---|
259 | { |
---|
260 | Objects_Name_to_id_errors status; |
---|
261 | |
---|
262 | status = _Objects_Name_to_id( |
---|
263 | &_Message_queue_Information, |
---|
264 | &name, |
---|
265 | node, |
---|
266 | id |
---|
267 | ); |
---|
268 | |
---|
269 | return _Status_Object_name_errors_to_status[ status ]; |
---|
270 | } |
---|
271 | |
---|
272 | /*PAGE |
---|
273 | * |
---|
274 | * rtems_message_queue_delete |
---|
275 | * |
---|
276 | * This directive allows a thread to delete the message queue specified |
---|
277 | * by the given queue identifier. |
---|
278 | * |
---|
279 | * Input parameters: |
---|
280 | * id - queue id |
---|
281 | * |
---|
282 | * Output parameters: |
---|
283 | * RTEMS_SUCCESSFUL - if successful |
---|
284 | * error code - if unsuccessful |
---|
285 | */ |
---|
286 | |
---|
287 | rtems_status_code rtems_message_queue_delete( |
---|
288 | Objects_Id id |
---|
289 | ) |
---|
290 | { |
---|
291 | register Message_queue_Control *the_message_queue; |
---|
292 | Objects_Locations location; |
---|
293 | |
---|
294 | the_message_queue = _Message_queue_Get( id, &location ); |
---|
295 | switch ( location ) { |
---|
296 | |
---|
297 | case OBJECTS_REMOTE: |
---|
298 | #if defined(RTEMS_MULTIPROCESSING) |
---|
299 | _Thread_Dispatch(); |
---|
300 | return RTEMS_ILLEGAL_ON_REMOTE_OBJECT; |
---|
301 | #endif |
---|
302 | |
---|
303 | case OBJECTS_ERROR: |
---|
304 | return RTEMS_INVALID_ID; |
---|
305 | |
---|
306 | case OBJECTS_LOCAL: |
---|
307 | _Objects_Close( &_Message_queue_Information, |
---|
308 | &the_message_queue->Object ); |
---|
309 | |
---|
310 | #if defined(RTEMS_MULTIPROCESSING) |
---|
311 | _CORE_message_queue_Close( |
---|
312 | &the_message_queue->message_queue, |
---|
313 | _Message_queue_MP_Send_object_was_deleted, |
---|
314 | CORE_MESSAGE_QUEUE_STATUS_WAS_DELETED |
---|
315 | ); |
---|
316 | #endif |
---|
317 | |
---|
318 | _Message_queue_Free( the_message_queue ); |
---|
319 | |
---|
320 | #if defined(RTEMS_MULTIPROCESSING) |
---|
321 | if ( _Attributes_Is_global( the_message_queue->attribute_set ) ) { |
---|
322 | _Objects_MP_Close( |
---|
323 | &_Message_queue_Information, |
---|
324 | the_message_queue->Object.id |
---|
325 | ); |
---|
326 | |
---|
327 | _Message_queue_MP_Send_process_packet( |
---|
328 | MESSAGE_QUEUE_MP_ANNOUNCE_DELETE, |
---|
329 | the_message_queue->Object.id, |
---|
330 | 0, /* Not used */ |
---|
331 | 0 |
---|
332 | ); |
---|
333 | } |
---|
334 | #endif |
---|
335 | |
---|
336 | _Thread_Enable_dispatch(); |
---|
337 | return RTEMS_SUCCESSFUL; |
---|
338 | } |
---|
339 | |
---|
340 | return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ |
---|
341 | } |
---|
342 | |
---|
343 | /*PAGE |
---|
344 | * |
---|
345 | * rtems_message_queue_send |
---|
346 | * |
---|
347 | * This routine implements the directives q_send. It sends a |
---|
348 | * message to the specified message queue. |
---|
349 | * |
---|
350 | * Input parameters: |
---|
351 | * id - pointer to message queue |
---|
352 | * buffer - pointer to message buffer |
---|
353 | * size - size of message to sent urgently |
---|
354 | * |
---|
355 | * Output parameters: |
---|
356 | * RTEMS_SUCCESSFUL - if successful |
---|
357 | * error code - if unsuccessful |
---|
358 | */ |
---|
359 | |
---|
360 | rtems_status_code rtems_message_queue_send( |
---|
361 | Objects_Id id, |
---|
362 | void *buffer, |
---|
363 | unsigned32 size |
---|
364 | ) |
---|
365 | { |
---|
366 | return( _Message_queue_Submit(id, buffer, size, MESSAGE_QUEUE_SEND_REQUEST) ); |
---|
367 | } |
---|
368 | |
---|
369 | /*PAGE |
---|
370 | * |
---|
371 | * rtems_message_queue_urgent |
---|
372 | * |
---|
373 | * This routine implements the directives q_urgent. It urgents a |
---|
374 | * message to the specified message queue. |
---|
375 | * |
---|
376 | * Input parameters: |
---|
377 | * id - pointer to message queue |
---|
378 | * buffer - pointer to message buffer |
---|
379 | * size - size of message to sent urgently |
---|
380 | * |
---|
381 | * Output parameters: |
---|
382 | * RTEMS_SUCCESSFUL - if successful |
---|
383 | * error code - if unsuccessful |
---|
384 | */ |
---|
385 | |
---|
386 | rtems_status_code rtems_message_queue_urgent( |
---|
387 | Objects_Id id, |
---|
388 | void *buffer, |
---|
389 | unsigned32 size |
---|
390 | ) |
---|
391 | { |
---|
392 | return(_Message_queue_Submit(id, buffer, size, MESSAGE_QUEUE_URGENT_REQUEST)); |
---|
393 | } |
---|
394 | |
---|
395 | /*PAGE |
---|
396 | * |
---|
397 | * rtems_message_queue_broadcast |
---|
398 | * |
---|
399 | * This directive sends a message for every thread waiting on the queue |
---|
400 | * designated by id. |
---|
401 | * |
---|
402 | * Input parameters: |
---|
403 | * id - pointer to message queue |
---|
404 | * buffer - pointer to message buffer |
---|
405 | * size - size of message to broadcast |
---|
406 | * count - pointer to area to store number of threads made ready |
---|
407 | * |
---|
408 | * Output parameters: |
---|
409 | * count - number of threads made ready |
---|
410 | * RTEMS_SUCCESSFUL - if successful |
---|
411 | * error code - if unsuccessful |
---|
412 | */ |
---|
413 | |
---|
414 | rtems_status_code rtems_message_queue_broadcast( |
---|
415 | Objects_Id id, |
---|
416 | void *buffer, |
---|
417 | unsigned32 size, |
---|
418 | unsigned32 *count |
---|
419 | ) |
---|
420 | { |
---|
421 | register Message_queue_Control *the_message_queue; |
---|
422 | Objects_Locations location; |
---|
423 | CORE_message_queue_Status core_status; |
---|
424 | |
---|
425 | the_message_queue = _Message_queue_Get( id, &location ); |
---|
426 | switch ( location ) { |
---|
427 | case OBJECTS_REMOTE: |
---|
428 | #if defined(RTEMS_MULTIPROCESSING) |
---|
429 | _Thread_Executing->Wait.return_argument = count; |
---|
430 | |
---|
431 | return |
---|
432 | _Message_queue_MP_Send_request_packet( |
---|
433 | MESSAGE_QUEUE_MP_BROADCAST_REQUEST, |
---|
434 | id, |
---|
435 | buffer, |
---|
436 | &size, |
---|
437 | 0, /* option_set not used */ |
---|
438 | MPCI_DEFAULT_TIMEOUT |
---|
439 | ); |
---|
440 | #endif |
---|
441 | |
---|
442 | case OBJECTS_ERROR: |
---|
443 | return RTEMS_INVALID_ID; |
---|
444 | |
---|
445 | case OBJECTS_LOCAL: |
---|
446 | core_status = _CORE_message_queue_Broadcast( |
---|
447 | &the_message_queue->message_queue, |
---|
448 | buffer, |
---|
449 | size, |
---|
450 | id, |
---|
451 | #if defined(RTEMS_MULTIPROCESSING) |
---|
452 | _Message_queue_Core_message_queue_mp_support, |
---|
453 | #else |
---|
454 | NULL, |
---|
455 | #endif |
---|
456 | count |
---|
457 | ); |
---|
458 | |
---|
459 | _Thread_Enable_dispatch(); |
---|
460 | return |
---|
461 | _Message_queue_Translate_core_message_queue_return_code( core_status ); |
---|
462 | |
---|
463 | } |
---|
464 | return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ |
---|
465 | } |
---|
466 | |
---|
467 | /*PAGE |
---|
468 | * |
---|
469 | * rtems_message_queue_receive |
---|
470 | * |
---|
471 | * This directive dequeues a message from the designated message queue |
---|
472 | * and copies it into the requesting thread's buffer. |
---|
473 | * |
---|
474 | * Input parameters: |
---|
475 | * id - queue id |
---|
476 | * buffer - pointer to message buffer |
---|
477 | * size - size of message receive |
---|
478 | * option_set - options on receive |
---|
479 | * timeout - number of ticks to wait |
---|
480 | * |
---|
481 | * Output parameters: |
---|
482 | * RTEMS_SUCCESSFUL - if successful |
---|
483 | * error code - if unsuccessful |
---|
484 | */ |
---|
485 | |
---|
486 | rtems_status_code rtems_message_queue_receive( |
---|
487 | Objects_Id id, |
---|
488 | void *buffer, |
---|
489 | unsigned32 *size, |
---|
490 | unsigned32 option_set, |
---|
491 | rtems_interval timeout |
---|
492 | ) |
---|
493 | { |
---|
494 | register Message_queue_Control *the_message_queue; |
---|
495 | Objects_Locations location; |
---|
496 | boolean wait; |
---|
497 | |
---|
498 | the_message_queue = _Message_queue_Get( id, &location ); |
---|
499 | switch ( location ) { |
---|
500 | |
---|
501 | case OBJECTS_REMOTE: |
---|
502 | #if defined(RTEMS_MULTIPROCESSING) |
---|
503 | return _Message_queue_MP_Send_request_packet( |
---|
504 | MESSAGE_QUEUE_MP_RECEIVE_REQUEST, |
---|
505 | id, |
---|
506 | buffer, |
---|
507 | size, |
---|
508 | option_set, |
---|
509 | timeout |
---|
510 | ); |
---|
511 | #endif |
---|
512 | |
---|
513 | case OBJECTS_ERROR: |
---|
514 | return RTEMS_INVALID_ID; |
---|
515 | |
---|
516 | case OBJECTS_LOCAL: |
---|
517 | if ( _Options_Is_no_wait( option_set ) ) |
---|
518 | wait = FALSE; |
---|
519 | else |
---|
520 | wait = TRUE; |
---|
521 | |
---|
522 | _CORE_message_queue_Seize( |
---|
523 | &the_message_queue->message_queue, |
---|
524 | the_message_queue->Object.id, |
---|
525 | buffer, |
---|
526 | size, |
---|
527 | wait, |
---|
528 | timeout |
---|
529 | ); |
---|
530 | _Thread_Enable_dispatch(); |
---|
531 | return( _Message_queue_Translate_core_message_queue_return_code( |
---|
532 | _Thread_Executing->Wait.return_code ) ); |
---|
533 | |
---|
534 | } |
---|
535 | |
---|
536 | return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ |
---|
537 | } |
---|
538 | |
---|
539 | /*PAGE |
---|
540 | * |
---|
541 | * rtems_message_queue_flush |
---|
542 | * |
---|
543 | * This directive removes all pending messages from a queue and returns |
---|
544 | * the number of messages removed. If no messages were present then |
---|
545 | * a count of zero is returned. |
---|
546 | * |
---|
547 | * Input parameters: |
---|
548 | * id - queue id |
---|
549 | * count - return area for count |
---|
550 | * |
---|
551 | * Output parameters: |
---|
552 | * count - number of messages removed ( 0 = empty queue ) |
---|
553 | * RTEMS_SUCCESSFUL - if successful |
---|
554 | * error code - if unsuccessful |
---|
555 | */ |
---|
556 | |
---|
557 | rtems_status_code rtems_message_queue_flush( |
---|
558 | Objects_Id id, |
---|
559 | unsigned32 *count |
---|
560 | ) |
---|
561 | { |
---|
562 | register Message_queue_Control *the_message_queue; |
---|
563 | Objects_Locations location; |
---|
564 | |
---|
565 | the_message_queue = _Message_queue_Get( id, &location ); |
---|
566 | switch ( location ) { |
---|
567 | case OBJECTS_REMOTE: |
---|
568 | #if defined(RTEMS_MULTIPROCESSING) |
---|
569 | _Thread_Executing->Wait.return_argument = count; |
---|
570 | |
---|
571 | return |
---|
572 | _Message_queue_MP_Send_request_packet( |
---|
573 | MESSAGE_QUEUE_MP_FLUSH_REQUEST, |
---|
574 | id, |
---|
575 | 0, /* buffer not used */ |
---|
576 | 0, /* size */ |
---|
577 | 0, /* option_set not used */ |
---|
578 | MPCI_DEFAULT_TIMEOUT |
---|
579 | ); |
---|
580 | #endif |
---|
581 | |
---|
582 | case OBJECTS_ERROR: |
---|
583 | return RTEMS_INVALID_ID; |
---|
584 | |
---|
585 | case OBJECTS_LOCAL: |
---|
586 | *count = _CORE_message_queue_Flush( &the_message_queue->message_queue ); |
---|
587 | _Thread_Enable_dispatch(); |
---|
588 | return RTEMS_SUCCESSFUL; |
---|
589 | } |
---|
590 | |
---|
591 | return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ |
---|
592 | } |
---|
593 | |
---|
594 | /*PAGE |
---|
595 | * |
---|
596 | * rtems_message_queue_get_number_pending |
---|
597 | * |
---|
598 | * This directive returns the number of messages pending. |
---|
599 | * |
---|
600 | * Input parameters: |
---|
601 | * id - queue id |
---|
602 | * count - return area for count |
---|
603 | * |
---|
604 | * Output parameters: |
---|
605 | * count - number of messages removed ( 0 = empty queue ) |
---|
606 | * RTEMS_SUCCESSFUL - if successful |
---|
607 | * error code - if unsuccessful |
---|
608 | */ |
---|
609 | |
---|
610 | rtems_status_code rtems_message_queue_get_number_pending( |
---|
611 | Objects_Id id, |
---|
612 | unsigned32 *count |
---|
613 | ) |
---|
614 | { |
---|
615 | register Message_queue_Control *the_message_queue; |
---|
616 | Objects_Locations location; |
---|
617 | |
---|
618 | the_message_queue = _Message_queue_Get( id, &location ); |
---|
619 | switch ( location ) { |
---|
620 | case OBJECTS_REMOTE: |
---|
621 | #if defined(RTEMS_MULTIPROCESSING) |
---|
622 | _Thread_Executing->Wait.return_argument = count; |
---|
623 | |
---|
624 | return _Message_queue_MP_Send_request_packet( |
---|
625 | MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_REQUEST, |
---|
626 | id, |
---|
627 | 0, /* buffer not used */ |
---|
628 | 0, /* size */ |
---|
629 | 0, /* option_set not used */ |
---|
630 | MPCI_DEFAULT_TIMEOUT |
---|
631 | ); |
---|
632 | #endif |
---|
633 | |
---|
634 | case OBJECTS_ERROR: |
---|
635 | return RTEMS_INVALID_ID; |
---|
636 | |
---|
637 | case OBJECTS_LOCAL: |
---|
638 | *count = the_message_queue->message_queue.number_of_pending_messages; |
---|
639 | _Thread_Enable_dispatch(); |
---|
640 | return RTEMS_SUCCESSFUL; |
---|
641 | } |
---|
642 | |
---|
643 | return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ |
---|
644 | } |
---|
645 | |
---|
646 | /*PAGE |
---|
647 | * |
---|
648 | * _Message_queue_Submit |
---|
649 | * |
---|
650 | * This routine implements the directives rtems_message_queue_send |
---|
651 | * and rtems_message_queue_urgent. It processes a message that is |
---|
652 | * to be submitted to the designated message queue. The message will |
---|
653 | * either be processed as a send send message which it will be inserted |
---|
654 | * at the rear of the queue or it will be processed as an urgent message |
---|
655 | * which will be inserted at the front of the queue. |
---|
656 | * |
---|
657 | * Input parameters: |
---|
658 | * id - pointer to message queue |
---|
659 | * buffer - pointer to message buffer |
---|
660 | * size - size in bytes of message to send |
---|
661 | * submit_type - send or urgent message |
---|
662 | * |
---|
663 | * Output parameters: |
---|
664 | * RTEMS_SUCCESSFUL - if successful |
---|
665 | * error code - if unsuccessful |
---|
666 | */ |
---|
667 | |
---|
668 | rtems_status_code _Message_queue_Submit( |
---|
669 | Objects_Id id, |
---|
670 | void *buffer, |
---|
671 | unsigned32 size, |
---|
672 | Message_queue_Submit_types submit_type |
---|
673 | ) |
---|
674 | { |
---|
675 | register Message_queue_Control *the_message_queue; |
---|
676 | Objects_Locations location; |
---|
677 | CORE_message_queue_Status core_status; |
---|
678 | |
---|
679 | the_message_queue = _Message_queue_Get( id, &location ); |
---|
680 | switch ( location ) |
---|
681 | { |
---|
682 | case OBJECTS_REMOTE: |
---|
683 | #if defined(RTEMS_MULTIPROCESSING) |
---|
684 | switch ( submit_type ) { |
---|
685 | case MESSAGE_QUEUE_SEND_REQUEST: |
---|
686 | return _Message_queue_MP_Send_request_packet( |
---|
687 | MESSAGE_QUEUE_MP_SEND_REQUEST, |
---|
688 | id, |
---|
689 | buffer, |
---|
690 | &size, |
---|
691 | 0, /* option_set */ |
---|
692 | MPCI_DEFAULT_TIMEOUT |
---|
693 | ); |
---|
694 | |
---|
695 | case MESSAGE_QUEUE_URGENT_REQUEST: |
---|
696 | return _Message_queue_MP_Send_request_packet( |
---|
697 | MESSAGE_QUEUE_MP_URGENT_REQUEST, |
---|
698 | id, |
---|
699 | buffer, |
---|
700 | &size, |
---|
701 | 0, /* option_set */ |
---|
702 | MPCI_DEFAULT_TIMEOUT |
---|
703 | ); |
---|
704 | } |
---|
705 | break; |
---|
706 | #endif |
---|
707 | |
---|
708 | case OBJECTS_ERROR: |
---|
709 | return RTEMS_INVALID_ID; |
---|
710 | |
---|
711 | case OBJECTS_LOCAL: |
---|
712 | switch ( submit_type ) { |
---|
713 | case MESSAGE_QUEUE_SEND_REQUEST: |
---|
714 | core_status = _CORE_message_queue_Send( |
---|
715 | &the_message_queue->message_queue, |
---|
716 | buffer, |
---|
717 | size, |
---|
718 | id, |
---|
719 | #if defined(RTEMS_MULTIPROCESSING) |
---|
720 | _Message_queue_Core_message_queue_mp_support |
---|
721 | #else |
---|
722 | NULL |
---|
723 | #endif |
---|
724 | ); |
---|
725 | break; |
---|
726 | case MESSAGE_QUEUE_URGENT_REQUEST: |
---|
727 | core_status = _CORE_message_queue_Urgent( |
---|
728 | &the_message_queue->message_queue, |
---|
729 | buffer, |
---|
730 | size, |
---|
731 | id, |
---|
732 | #if defined(RTEMS_MULTIPROCESSING) |
---|
733 | _Message_queue_Core_message_queue_mp_support |
---|
734 | #else |
---|
735 | NULL |
---|
736 | #endif |
---|
737 | ); |
---|
738 | break; |
---|
739 | default: |
---|
740 | core_status = CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL; |
---|
741 | return RTEMS_INTERNAL_ERROR; /* should never get here */ |
---|
742 | } |
---|
743 | |
---|
744 | _Thread_Enable_dispatch(); |
---|
745 | return _Message_queue_Translate_core_message_queue_return_code( |
---|
746 | core_status ); |
---|
747 | |
---|
748 | } |
---|
749 | return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ |
---|
750 | } |
---|
751 | |
---|
752 | /*PAGE |
---|
753 | * |
---|
754 | * _Message_queue_Translate_core_message_queue_return_code |
---|
755 | * |
---|
756 | * Input parameters: |
---|
757 | * the_message_queue_status - message_queue status code to translate |
---|
758 | * |
---|
759 | * Output parameters: |
---|
760 | * rtems status code - translated RTEMS status code |
---|
761 | * |
---|
762 | */ |
---|
763 | |
---|
764 | rtems_status_code _Message_queue_Translate_core_message_queue_return_code ( |
---|
765 | unsigned32 the_message_queue_status |
---|
766 | ) |
---|
767 | { |
---|
768 | switch ( the_message_queue_status ) { |
---|
769 | case CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL: |
---|
770 | return RTEMS_SUCCESSFUL; |
---|
771 | case CORE_MESSAGE_QUEUE_STATUS_INVALID_SIZE: |
---|
772 | return RTEMS_INVALID_SIZE; |
---|
773 | case CORE_MESSAGE_QUEUE_STATUS_TOO_MANY: |
---|
774 | return RTEMS_TOO_MANY; |
---|
775 | case CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED: |
---|
776 | return RTEMS_UNSATISFIED; |
---|
777 | case CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_NOWAIT: |
---|
778 | return RTEMS_UNSATISFIED; |
---|
779 | case CORE_MESSAGE_QUEUE_STATUS_WAS_DELETED: |
---|
780 | return RTEMS_OBJECT_WAS_DELETED; |
---|
781 | case CORE_MESSAGE_QUEUE_STATUS_TIMEOUT: |
---|
782 | return RTEMS_TIMEOUT; |
---|
783 | case THREAD_STATUS_PROXY_BLOCKING: |
---|
784 | return RTEMS_PROXY_BLOCKING; |
---|
785 | } |
---|
786 | _Internal_error_Occurred( /* XXX */ |
---|
787 | INTERNAL_ERROR_RTEMS_API, |
---|
788 | TRUE, |
---|
789 | the_message_queue_status |
---|
790 | ); |
---|
791 | return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ |
---|
792 | } |
---|
793 | |
---|
794 | /*PAGE |
---|
795 | * |
---|
796 | * _Message_queue_Core_message_queue_mp_support |
---|
797 | * |
---|
798 | * Input parameters: |
---|
799 | * the_thread - the remote thread the message was submitted to |
---|
800 | * id - id of the message queue |
---|
801 | * |
---|
802 | * Output parameters: NONE |
---|
803 | */ |
---|
804 | |
---|
805 | #if defined(RTEMS_MULTIPROCESSING) |
---|
806 | void _Message_queue_Core_message_queue_mp_support ( |
---|
807 | Thread_Control *the_thread, |
---|
808 | Objects_Id id |
---|
809 | ) |
---|
810 | { |
---|
811 | the_thread->receive_packet->return_code = RTEMS_SUCCESSFUL; |
---|
812 | |
---|
813 | _Message_queue_MP_Send_response_packet( |
---|
814 | MESSAGE_QUEUE_MP_RECEIVE_RESPONSE, |
---|
815 | id, |
---|
816 | the_thread |
---|
817 | ); |
---|
818 | } |
---|
819 | #endif |
---|