source: rtems/cpukit/score/src/coremsgsubmit.c @ 1b7a6a38

5
Last change on this file since 1b7a6a38 was 1b7a6a38, checked in by Sebastian Huber <sebastian.huber@…>, on 04/29/16 at 08:28:31

score: _CORE_message_queue_Set_message_priority()

Remove _CORE_message_queue_Set_message_priority() and set the priority
in _CORE_message_queue_Insert_message().

  • Property mode set to 100644
File size: 3.8 KB
Line 
1/**
2 * @file
3 *
4 * @brief CORE Message Queue Submit
5 *
6 * @ingroup ScoreMessageQueue
7 */
8
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.org/license/LICENSE.
16 */
17
18#if HAVE_CONFIG_H
19#include "config.h"
20#endif
21
22#include <rtems/score/coremsgimpl.h>
23#include <rtems/score/objectimpl.h>
24#include <rtems/score/isr.h>
25#include <rtems/score/statesimpl.h>
26#include <rtems/score/wkspace.h>
27
28CORE_message_queue_Status _CORE_message_queue_Do_submit(
29  CORE_message_queue_Control       *the_message_queue,
30  Thread_Control                   *executing,
31  const void                       *buffer,
32  size_t                            size,
33#if defined(RTEMS_MULTIPROCESSING)
34  Thread_queue_MP_callout           mp_callout,
35  Objects_Id                        mp_id,
36#endif
37  CORE_message_queue_Submit_types   submit_type,
38  bool                              wait,
39  Watchdog_Interval                 timeout,
40  ISR_lock_Context                 *lock_context
41)
42{
43  CORE_message_queue_Buffer_control *the_message;
44  Thread_Control                    *the_thread;
45
46  if ( size > the_message_queue->maximum_message_size ) {
47    _CORE_message_queue_Release( the_message_queue, lock_context );
48    return CORE_MESSAGE_QUEUE_STATUS_INVALID_SIZE;
49  }
50
51  /*
52   *  Is there a thread currently waiting on this message queue?
53   */
54
55  the_thread = _CORE_message_queue_Dequeue_receiver(
56    the_message_queue,
57    buffer,
58    size,
59    mp_callout,
60    mp_id,
61    submit_type,
62    lock_context
63  );
64  if ( the_thread != NULL ) {
65    return CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL;
66  }
67
68  /*
69   *  No one waiting on the message queue at this time, so attempt to
70   *  queue the message up for a future receive.
71   */
72  the_message =
73      _CORE_message_queue_Allocate_message_buffer( the_message_queue );
74  if ( the_message ) {
75    the_message->Contents.size = size;
76    _CORE_message_queue_Copy_buffer(
77      buffer,
78      the_message->Contents.buffer,
79      size
80    );
81    _CORE_message_queue_Insert_message(
82       the_message_queue,
83       the_message,
84       submit_type
85    );
86    _CORE_message_queue_Release( the_message_queue, lock_context );
87    return CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL;
88  }
89
90  #if !defined(RTEMS_SCORE_COREMSG_ENABLE_BLOCKING_SEND)
91    _CORE_message_queue_Release( the_message_queue, lock_context );
92    return CORE_MESSAGE_QUEUE_STATUS_TOO_MANY;
93  #else
94    /*
95     *  No message buffers were available so we may need to return an
96     *  overflow error or block the sender until the message is placed
97     *  on the queue.
98     */
99    if ( !wait ) {
100      _CORE_message_queue_Release( the_message_queue, lock_context );
101      return CORE_MESSAGE_QUEUE_STATUS_TOO_MANY;
102    }
103
104    /*
105     *  Do NOT block on a send if the caller is in an ISR.  It is
106     *  deadly to block in an ISR.
107     */
108    if ( _ISR_Is_in_progress() ) {
109      _CORE_message_queue_Release( the_message_queue, lock_context );
110      return CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED;
111    }
112
113    /*
114     *  WARNING!! executing should NOT be used prior to this point.
115     *  Thus the unusual choice to open a new scope and declare
116     *  it as a variable.  Doing this emphasizes how dangerous it
117     *  would be to use this variable prior to here.
118     */
119    executing->Wait.return_argument_second.immutable_object = buffer;
120    executing->Wait.option = (uint32_t) size;
121    executing->Wait.count = submit_type;
122
123    _Thread_queue_Enqueue_critical(
124      &the_message_queue->Wait_queue.Queue,
125      the_message_queue->operations,
126      executing,
127      STATES_WAITING_FOR_MESSAGE,
128      timeout,
129      CORE_MESSAGE_QUEUE_STATUS_TIMEOUT,
130      lock_context
131    );
132    return CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_WAIT;
133  #endif
134}
Note: See TracBrowser for help on using the repository browser.