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

4.104.115
Last change on this file since f0b14cf2 was f0b14cf2, checked in by Ralf Corsepius <ralf.corsepius@…>, on 12/31/08 at 03:24:18

Add attribute((unused)) to unused function args.

  • 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    /*
115     *  NOTE: If the system is consistent, this error should never occur.
116     */
117
118    if ( !the_message ) {
119      return CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED;
120    }
121
122    _CORE_message_queue_Copy_buffer(
123      buffer,
124      the_message->Contents.buffer,
125      size
126    );
127    the_message->Contents.size = size;
128    the_message->priority  = submit_type;
129
130    _CORE_message_queue_Insert_message(
131       the_message_queue,
132       the_message,
133       submit_type
134    );
135    return CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL;
136  }
137
138  /*
139   *  No message buffers were available so we may need to return an
140   *  overflow error or block the sender until the message is placed
141   *  on the queue.
142   */
143
144  if ( !wait ) {
145    return CORE_MESSAGE_QUEUE_STATUS_TOO_MANY;
146  }
147
148  /*
149   *  Do NOT block on a send if the caller is in an ISR.  It is
150   *  deadly to block in an ISR.
151   */
152
153  if ( _ISR_Is_in_progress() ) {
154    return CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED;
155  }
156
157  /*
158   *  WARNING!! executing should NOT be used prior to this point.
159   *  Thus the unusual choice to open a new scope and declare
160   *  it as a variable.  Doing this emphasizes how dangerous it
161   *  would be to use this variable prior to here.
162   */
163
164  {
165    Thread_Control  *executing = _Thread_Executing;
166
167    _ISR_Disable( level );
168    _Thread_queue_Enter_critical_section( &the_message_queue->Wait_queue );
169    executing->Wait.queue = &the_message_queue->Wait_queue;
170    executing->Wait.id = id;
171    executing->Wait.return_argument_second.immutable_object = buffer;
172    executing->Wait.option = (uint32_t) size;
173    executing->Wait.count = submit_type;
174    _ISR_Enable( level );
175
176    _Thread_queue_Enqueue( &the_message_queue->Wait_queue, timeout );
177  }
178
179  return CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_WAIT;
180}
Note: See TracBrowser for help on using the repository browser.