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

4.104.114.95
Last change on this file since b3836ce was b3836ce, checked in by Joel Sherrill <joel.sherrill@…>, on 09/05/08 at 21:54:20

2008-09-05 Joel Sherrill <joel.sherrill@…>

  • score/src/corebarrier.c, score/src/corebarrierrelease.c, score/src/corebarrierwait.c, score/src/coremsg.c, score/src/coremsgbroadcast.c, score/src/coremsgclose.c, score/src/coremsgflush.c, score/src/coremsgflushsupp.c, score/src/coremsgflushwait.c, score/src/coremsginsert.c, score/src/coremsgseize.c, score/src/coremsgsubmit.c, score/src/corerwlock.c, score/src/coresem.c, score/src/coresemflush.c, score/src/coresemseize.c, score/src/coresemsurrender.c, score/src/corespinlock.c, score/src/threadblockingoperationcancel.c, score/src/threadqenqueue.c: Remove unnecessary include of mpci.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
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  CORE_message_queue_API_mp_support_callout  api_message_queue_mp_support,
63  CORE_message_queue_Submit_types            submit_type,
64  bool                                       wait,
65  Watchdog_Interval                          timeout
66)
67{
68  ISR_Level                            level;
69  CORE_message_queue_Buffer_control   *the_message;
70  Thread_Control                      *the_thread;
71
72  if ( size > the_message_queue->maximum_message_size ) {
73    return CORE_MESSAGE_QUEUE_STATUS_INVALID_SIZE;
74  }
75
76  /*
77   *  Is there a thread currently waiting on this message queue?
78   */
79
80  if ( the_message_queue->number_of_pending_messages == 0 ) {
81    the_thread = _Thread_queue_Dequeue( &the_message_queue->Wait_queue );
82    if ( the_thread ) {
83      _CORE_message_queue_Copy_buffer(
84        buffer,
85        the_thread->Wait.return_argument_second.mutable_object,
86        size
87      );
88      *(size_t *) the_thread->Wait.return_argument = size;
89      the_thread->Wait.count = submit_type;
90
91#if defined(RTEMS_MULTIPROCESSING)
92      if ( !_Objects_Is_local_id( the_thread->Object.id ) )
93        (*api_message_queue_mp_support) ( the_thread, id );
94#endif
95      return CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL;
96    }
97  }
98
99  /*
100   *  No one waiting on the message queue at this time, so attempt to
101   *  queue the message up for a future receive.
102   */
103
104  if ( the_message_queue->number_of_pending_messages <
105       the_message_queue->maximum_pending_messages ) {
106
107    the_message =
108        _CORE_message_queue_Allocate_message_buffer( the_message_queue );
109
110    /*
111     *  NOTE: If the system is consistent, this error should never occur.
112     */
113
114    if ( !the_message ) {
115      return CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED;
116    }
117
118    _CORE_message_queue_Copy_buffer(
119      buffer,
120      the_message->Contents.buffer,
121      size
122    );
123    the_message->Contents.size = size;
124    the_message->priority  = submit_type;
125
126    _CORE_message_queue_Insert_message(
127       the_message_queue,
128       the_message,
129       submit_type
130    );
131    return CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL;
132  }
133
134  /*
135   *  No message buffers were available so we may need to return an
136   *  overflow error or block the sender until the message is placed
137   *  on the queue.
138   */
139
140  if ( !wait ) {
141    return CORE_MESSAGE_QUEUE_STATUS_TOO_MANY;
142  }
143
144  /*
145   *  Do NOT block on a send if the caller is in an ISR.  It is
146   *  deadly to block in an ISR.
147   */
148
149  if ( _ISR_Is_in_progress() ) {
150    return CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED;
151  }
152
153  /*
154   *  WARNING!! executing should NOT be used prior to this point.
155   *  Thus the unusual choice to open a new scope and declare
156   *  it as a variable.  Doing this emphasizes how dangerous it
157   *  would be to use this variable prior to here.
158   */
159
160  {
161    Thread_Control  *executing = _Thread_Executing;
162
163    _ISR_Disable( level );
164    _Thread_queue_Enter_critical_section( &the_message_queue->Wait_queue );
165    executing->Wait.queue = &the_message_queue->Wait_queue;
166    executing->Wait.id = id;
167    executing->Wait.return_argument_second.immutable_object = buffer;
168    executing->Wait.option = (uint32_t) size;
169    executing->Wait.count = submit_type;
170    _ISR_Enable( level );
171
172    _Thread_queue_Enqueue( &the_message_queue->Wait_queue, timeout );
173  }
174
175  return CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_WAIT;
176}
Note: See TracBrowser for help on using the repository browser.