source: rtems/cpukit/score/src/coremsgsubmit.c @ 5a6d25fc

4.104.115
Last change on this file since 5a6d25fc was 507d382, checked in by Joel Sherrill <joel.sherrill@…>, on 09/11/09 at 20:00:30

2009-09-11 Joel Sherrill <joel.sherrill@…>

  • score/include/rtems/score/coremsg.h, score/inline/rtems/score/coremsg.inl, score/src/coremsg.c, score/src/coremsginsert.c, score/src/coremsgseize.c, score/src/coremsgsubmit.c, score/src/objectnametoidstring.c: Disable the Core Message Queue features of notification, priority messages, and blocking sends when no API requires them.
  • Property mode set to 100644
File size: 5.7 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-2009.
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  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  if ( the_message_queue->number_of_pending_messages == 0 ) {
83    the_thread = _Thread_queue_Dequeue( &the_message_queue->Wait_queue );
84    if ( the_thread ) {
85      _CORE_message_queue_Copy_buffer(
86        buffer,
87        the_thread->Wait.return_argument_second.mutable_object,
88        size
89      );
90      *(size_t *) the_thread->Wait.return_argument = size;
91      the_thread->Wait.count = submit_type;
92
93#if defined(RTEMS_MULTIPROCESSING)
94      if ( !_Objects_Is_local_id( the_thread->Object.id ) )
95        (*api_message_queue_mp_support) ( the_thread, id );
96#endif
97      return CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL;
98    }
99  }
100
101  /*
102   *  No one waiting on the message queue at this time, so attempt to
103   *  queue the message up for a future receive.
104   */
105  if ( the_message_queue->number_of_pending_messages <
106       the_message_queue->maximum_pending_messages ) {
107
108    the_message =
109        _CORE_message_queue_Allocate_message_buffer( the_message_queue );
110
111    #if defined(RTEMS_DEBUG)
112      /*
113       *  NOTE: If the system is consistent, this error should never occur.
114       */
115
116      if ( !the_message )
117        return CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED;
118     #endif
119
120    _CORE_message_queue_Copy_buffer(
121      buffer,
122      the_message->Contents.buffer,
123      size
124    );
125    the_message->Contents.size = size;
126    #if defined(RTEMS_SCORE_COREMSG_ENABLE_MESSAGE_PRIORITY)
127      the_message->priority  = submit_type;
128    #endif
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  #if !defined(RTEMS_SCORE_COREMSG_ENABLE_BLOCKING_SEND)
139    return CORE_MESSAGE_QUEUE_STATUS_TOO_MANY;
140  #else
141    /*
142     *  No message buffers were available so we may need to return an
143     *  overflow error or block the sender until the message is placed
144     *  on the queue.
145     */
146    if ( !wait ) {
147      return CORE_MESSAGE_QUEUE_STATUS_TOO_MANY;
148    }
149
150    /*
151     *  Do NOT block on a send if the caller is in an ISR.  It is
152     *  deadly to block in an ISR.
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      Thread_Control  *executing = _Thread_Executing;
166      ISR_Level        level;
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  #endif
182}
Note: See TracBrowser for help on using the repository browser.