source: rtems/cpukit/score/src/coremsgsubmit.c @ b094233

4.104.115
Last change on this file since b094233 was 402dad51, checked in by Joel Sherrill <joel.sherrill@…>, on 07/06/09 at 16:44:49

2009-07-06 Joel Sherrill <joel.sherrill@…>

  • score/src/coremsgsubmit.c: Move impossible case inside an RTEMS_DEBUG conditional.
  • Property mode set to 100644
File size: 5.4 KB
Line 
1/*
2 *  CORE Message Queue Handler
3 *
4 *  DESCRIPTION:
5 *
6 *  This package is the implementation of the CORE Message Queue Handler.
7 *  This core object provides task synchronization and communication functions
8 *  via messages passed to queue objects.
9 *
10 *  COPYRIGHT (c) 1989-1999.
11 *  On-Line Applications Research Corporation (OAR).
12 *
13 *  The license and distribution terms for this file may be
14 *  found in the file LICENSE in this distribution or at
15 *  http://www.rtems.com/license/LICENSE.
16 *
17 *  $Id$
18 */
19
20#if HAVE_CONFIG_H
21#include "config.h"
22#endif
23
24#include <rtems/system.h>
25#include <rtems/score/chain.h>
26#include <rtems/score/isr.h>
27#include <rtems/score/object.h>
28#include <rtems/score/coremsg.h>
29#include <rtems/score/states.h>
30#include <rtems/score/thread.h>
31#include <rtems/score/wkspace.h>
32
33/*PAGE
34 *
35 *  _CORE_message_queue_Submit
36 *
37 *  This routine implements the send and urgent message functions. It
38 *  processes a message that is to be submitted to the designated
39 *  message queue.  The message will either be processed as a
40 *  send message which it will be inserted at the rear of the queue
41 *  or it will be processed as an urgent message which will be inserted
42 *  at the front of the queue.
43 *
44 *  Input parameters:
45 *    the_message_queue            - message is submitted to this message queue
46 *    buffer                       - pointer to message buffer
47 *    size                         - size in bytes of message to send
48 *    id                           - id of message queue
49 *    api_message_queue_mp_support - api specific mp support callout
50 *    submit_type                  - send or urgent message
51 *
52 *  Output parameters:
53 *    CORE_MESSAGE_QUEUE_SUCCESSFUL - if successful
54 *    error code                    - if unsuccessful
55 */
56
57CORE_message_queue_Status _CORE_message_queue_Submit(
58  CORE_message_queue_Control                *the_message_queue,
59  const void                                *buffer,
60  size_t                                     size,
61  Objects_Id                                 id,
62#if defined(RTEMS_MULTIPROCESSING)
63  CORE_message_queue_API_mp_support_callout  api_message_queue_mp_support,
64#else
65  CORE_message_queue_API_mp_support_callout  api_message_queue_mp_support __attribute__((unused)),
66#endif
67  CORE_message_queue_Submit_types            submit_type,
68  bool                                       wait,
69  Watchdog_Interval                          timeout
70)
71{
72  ISR_Level                            level;
73  CORE_message_queue_Buffer_control   *the_message;
74  Thread_Control                      *the_thread;
75
76  if ( size > the_message_queue->maximum_message_size ) {
77    return CORE_MESSAGE_QUEUE_STATUS_INVALID_SIZE;
78  }
79
80  /*
81   *  Is there a thread currently waiting on this message queue?
82   */
83
84  if ( the_message_queue->number_of_pending_messages == 0 ) {
85    the_thread = _Thread_queue_Dequeue( &the_message_queue->Wait_queue );
86    if ( the_thread ) {
87      _CORE_message_queue_Copy_buffer(
88        buffer,
89        the_thread->Wait.return_argument_second.mutable_object,
90        size
91      );
92      *(size_t *) the_thread->Wait.return_argument = size;
93      the_thread->Wait.count = submit_type;
94
95#if defined(RTEMS_MULTIPROCESSING)
96      if ( !_Objects_Is_local_id( the_thread->Object.id ) )
97        (*api_message_queue_mp_support) ( the_thread, id );
98#endif
99      return CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL;
100    }
101  }
102
103  /*
104   *  No one waiting on the message queue at this time, so attempt to
105   *  queue the message up for a future receive.
106   */
107
108  if ( the_message_queue->number_of_pending_messages <
109       the_message_queue->maximum_pending_messages ) {
110
111    the_message =
112        _CORE_message_queue_Allocate_message_buffer( the_message_queue );
113
114    #if defined(RTEMS_DEBUG)
115      /*
116       *  NOTE: If the system is consistent, this error should never occur.
117       */
118
119      if ( !the_message )
120        return CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED;
121     #endif
122
123    _CORE_message_queue_Copy_buffer(
124      buffer,
125      the_message->Contents.buffer,
126      size
127    );
128    the_message->Contents.size = size;
129    the_message->priority  = submit_type;
130
131    _CORE_message_queue_Insert_message(
132       the_message_queue,
133       the_message,
134       submit_type
135    );
136    return CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL;
137  }
138
139  /*
140   *  No message buffers were available so we may need to return an
141   *  overflow error or block the sender until the message is placed
142   *  on the queue.
143   */
144
145  if ( !wait ) {
146    return CORE_MESSAGE_QUEUE_STATUS_TOO_MANY;
147  }
148
149  /*
150   *  Do NOT block on a send if the caller is in an ISR.  It is
151   *  deadly to block in an ISR.
152   */
153
154  if ( _ISR_Is_in_progress() ) {
155    return CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED;
156  }
157
158  /*
159   *  WARNING!! executing should NOT be used prior to this point.
160   *  Thus the unusual choice to open a new scope and declare
161   *  it as a variable.  Doing this emphasizes how dangerous it
162   *  would be to use this variable prior to here.
163   */
164
165  {
166    Thread_Control  *executing = _Thread_Executing;
167
168    _ISR_Disable( level );
169    _Thread_queue_Enter_critical_section( &the_message_queue->Wait_queue );
170    executing->Wait.queue = &the_message_queue->Wait_queue;
171    executing->Wait.id = id;
172    executing->Wait.return_argument_second.immutable_object = buffer;
173    executing->Wait.option = (uint32_t) size;
174    executing->Wait.count = submit_type;
175    _ISR_Enable( level );
176
177    _Thread_queue_Enqueue( &the_message_queue->Wait_queue, timeout );
178  }
179
180  return CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_WAIT;
181}
Note: See TracBrowser for help on using the repository browser.