source: rtems/cpukit/score/src/coremsgsubmit.c @ 4e97166

4.104.114.84.95
Last change on this file since 4e97166 was a8eed23, checked in by Ralf Corsepius <ralf.corsepius@…>, on 01/27/05 at 05:57:05

Include config.h.

  • Property mode set to 100644
File size: 5.3 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#if defined(RTEMS_MULTIPROCESSING)
33#include <rtems/score/mpci.h>
34#endif
35
36/*PAGE
37 *
38 *  _CORE_message_queue_Submit
39 *
40 *  This routine implements the send and urgent message functions. It
41 *  processes a message that is to be submitted to the designated
42 *  message queue.  The message will either be processed as a
43 *  send message which it will be inserted at the rear of the queue
44 *  or it will be processed as an urgent message which will be inserted
45 *  at the front of the queue.
46 *
47 *  Input parameters:
48 *    the_message_queue            - message is submitted to this message queue
49 *    buffer                       - pointer to message buffer
50 *    size                         - size in bytes of message to send
51 *    id                           - id of message queue
52 *    api_message_queue_mp_support - api specific mp support callout
53 *    submit_type                  - send or urgent message
54 *
55 *  Output parameters:
56 *    CORE_MESSAGE_QUEUE_SUCCESSFUL - if successful
57 *    error code                    - if unsuccessful
58 */
59
60CORE_message_queue_Status _CORE_message_queue_Submit(
61  CORE_message_queue_Control                *the_message_queue,
62  void                                      *buffer,
63  uint32_t                                   size,
64  Objects_Id                                 id,
65  CORE_message_queue_API_mp_support_callout  api_message_queue_mp_support,
66  CORE_message_queue_Submit_types            submit_type,
67  boolean                                    wait,
68  Watchdog_Interval                          timeout
69)
70{
71  ISR_Level                            level;
72  CORE_message_queue_Buffer_control   *the_message;
73  Thread_Control                      *the_thread;
74
75  if ( size > the_message_queue->maximum_message_size ) {
76    return CORE_MESSAGE_QUEUE_STATUS_INVALID_SIZE;
77  }
78
79  /*
80   *  Is there a thread currently waiting on this message queue?
81   */
82
83  if ( the_message_queue->number_of_pending_messages == 0 ) {
84    the_thread = _Thread_queue_Dequeue( &the_message_queue->Wait_queue );
85    if ( the_thread ) {
86      _CORE_message_queue_Copy_buffer(
87        buffer,
88        the_thread->Wait.return_argument,
89        size
90      );
91      *(uint32_t   *)the_thread->Wait.return_argument_1 = size;
92      the_thread->Wait.count = submit_type;
93
94#if defined(RTEMS_MULTIPROCESSING)
95      if ( !_Objects_Is_local_id( the_thread->Object.id ) )
96        (*api_message_queue_mp_support) ( the_thread, id );
97#endif
98      return CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL;
99    }
100  }
101
102  /*
103   *  No one waiting on the message queue at this time, so attempt to
104   *  queue the message up for a future receive.
105   */
106
107  if ( the_message_queue->number_of_pending_messages <
108       the_message_queue->maximum_pending_messages ) {
109
110    the_message =
111        _CORE_message_queue_Allocate_message_buffer( the_message_queue );
112
113    /*
114     *  NOTE: If the system is consistent, this error should never occur.
115     */
116
117    if ( !the_message ) {
118      return CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED;
119    }
120
121    _CORE_message_queue_Copy_buffer(
122      buffer,
123      the_message->Contents.buffer,
124      size
125    );
126    the_message->Contents.size = size;
127    the_message->priority  = submit_type;
128
129    _CORE_message_queue_Insert_message(
130       the_message_queue,
131       the_message,
132       submit_type
133    );
134    return CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL;
135  }
136
137  /*
138   *  No message buffers were available so we may need to return an
139   *  overflow error or block the sender until the message is placed
140   *  on the queue.
141   */
142
143  if ( !wait ) {
144    return CORE_MESSAGE_QUEUE_STATUS_TOO_MANY;
145  }
146
147  /*
148   *  Do NOT block on a send if the caller is in an ISR.  It is
149   *  deadly to block in an ISR.
150   */
151
152  if ( _ISR_Is_in_progress() ) {
153    return CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED;
154  }
155
156  /*
157   *  WARNING!! executing should NOT be used prior to this point.
158   *  Thus the unusual choice to open a new scope and declare
159   *  it as a variable.  Doing this emphasizes how dangerous it
160   *  would be to use this variable prior to here.
161   */
162
163  {
164    Thread_Control  *executing = _Thread_Executing;
165
166    _ISR_Disable( level );
167    _Thread_queue_Enter_critical_section( &the_message_queue->Wait_queue );
168    executing->Wait.queue              = &the_message_queue->Wait_queue;
169    executing->Wait.id                 = id;
170    executing->Wait.return_argument    = buffer;
171    executing->Wait.return_argument_1  = (void *)size;
172    executing->Wait.count              = submit_type;
173    _ISR_Enable( level );
174
175    _Thread_queue_Enqueue( &the_message_queue->Wait_queue, timeout );
176  }
177
178  return CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_WAIT;
179}
Note: See TracBrowser for help on using the repository browser.