source: rtems/cpukit/rtems/src/msg.c @ fdd9fe17

4.104.114.84.95
Last change on this file since fdd9fe17 was fdd9fe17, checked in by Joel Sherrill <joel.sherrill@…>, on 12/03/98 at 21:52:20

Corrected ifdef on RTEMS_MULTIPROCESSING so the queue is actually closed.

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