source: rtems/cpukit/score/src/coremsginsert.c @ 25f5730f

4.11
Last change on this file since 25f5730f was c499856, checked in by Chris Johns <chrisj@…>, on Mar 20, 2014 at 9:10:47 PM

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 3.5 KB
Line 
1/**
2 * @file
3 *
4 * @brief Insert a Message into the Message Queue
5 * @ingroup ScoreMessageQueue
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2005.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.org/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <rtems/system.h>
22#include <rtems/score/chain.h>
23#include <rtems/score/isr.h>
24#include <rtems/score/coremsgimpl.h>
25#include <rtems/score/thread.h>
26#include <rtems/score/wkspace.h>
27
28void _CORE_message_queue_Insert_message(
29  CORE_message_queue_Control        *the_message_queue,
30  CORE_message_queue_Buffer_control *the_message,
31  CORE_message_queue_Submit_types    submit_type
32)
33{
34  ISR_Level  level;
35  #if defined(RTEMS_SCORE_COREMSG_ENABLE_NOTIFICATION)
36    bool    notify = false;
37    #define SET_NOTIFY() \
38      do { \
39        if ( the_message_queue->number_of_pending_messages == 0 ) \
40          notify = true; \
41      } while (0)
42  #else
43    #define SET_NOTIFY()
44  #endif
45
46  _CORE_message_queue_Set_message_priority( the_message, submit_type );
47
48  #if !defined(RTEMS_SCORE_COREMSG_ENABLE_MESSAGE_PRIORITY)
49    _ISR_Disable( level );
50      SET_NOTIFY();
51      the_message_queue->number_of_pending_messages++;
52      if ( submit_type == CORE_MESSAGE_QUEUE_SEND_REQUEST )
53        _CORE_message_queue_Append_unprotected(the_message_queue, the_message);
54      else
55        _CORE_message_queue_Prepend_unprotected(the_message_queue, the_message);
56    _ISR_Enable( level );
57  #else
58    if ( submit_type == CORE_MESSAGE_QUEUE_SEND_REQUEST ) {
59      _ISR_Disable( level );
60        SET_NOTIFY();
61        the_message_queue->number_of_pending_messages++;
62        _CORE_message_queue_Append_unprotected(the_message_queue, the_message);
63      _ISR_Enable( level );
64    } else if ( submit_type == CORE_MESSAGE_QUEUE_URGENT_REQUEST ) {
65      _ISR_Disable( level );
66        SET_NOTIFY();
67        the_message_queue->number_of_pending_messages++;
68        _CORE_message_queue_Prepend_unprotected(the_message_queue, the_message);
69      _ISR_Enable( level );
70    } else {
71      CORE_message_queue_Buffer_control *this_message;
72      Chain_Node                        *the_node;
73      Chain_Control                     *the_header;
74      int                                the_priority;
75
76      the_priority = _CORE_message_queue_Get_message_priority(the_message);
77      the_header = &the_message_queue->Pending_messages;
78      the_node = _Chain_First( the_header );
79      while ( !_Chain_Is_tail( the_header, the_node ) ) {
80        int this_priority;
81
82        this_message = (CORE_message_queue_Buffer_control *) the_node;
83
84        this_priority = _CORE_message_queue_Get_message_priority(this_message);
85
86        if ( this_priority <= the_priority ) {
87          the_node = the_node->next;
88          continue;
89        }
90        break;
91      }
92      _ISR_Disable( level );
93        SET_NOTIFY();
94        the_message_queue->number_of_pending_messages++;
95        _Chain_Insert_unprotected( the_node->previous, &the_message->Node );
96      _ISR_Enable( level );
97    }
98  #endif
99
100  #if defined(RTEMS_SCORE_COREMSG_ENABLE_NOTIFICATION)
101    /*
102     *  According to POSIX, does this happen before or after the message
103     *  is actually enqueued.  It is logical to think afterwards, because
104     *  the message is actually in the queue at this point.
105     */
106    if ( notify && the_message_queue->notify_handler )
107      (*the_message_queue->notify_handler)(the_message_queue->notify_argument);
108  #endif
109}
Note: See TracBrowser for help on using the repository browser.