source: rtems/cpukit/score/src/coremsginsert.c @ 749d64a

4.104.115
Last change on this file since 749d64a was 939ba81, checked in by Joel Sherrill <joel.sherrill@…>, on 09/13/09 at 16:05:14

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

  • score/inline/rtems/score/coremsg.inl, score/src/coremsg.c, score/src/coremsgbroadcast.c, score/src/coremsginsert.c, score/src/coremsgseize.c, score/src/coremsgsubmit.c: Add wrappers for accessing message priority. Since these are empty when priority-based message queues are disabled, this eliminates some of the conditionals.
  • Property mode set to 100644
File size: 4.1 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-2005.
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_Insert_message
36 *
37 *  This kernel routine inserts the specified message into the
38 *  message queue.  It is assumed that the message has been filled
39 *  in before this routine is called.
40 *
41 *  Input parameters:
42 *    the_message_queue - pointer to message queue
43 *    the_message       - message to insert
44 *    priority          - insert indication
45 *
46 *  Output parameters:  NONE
47 *
48 *  INTERRUPT LATENCY:
49 *    insert
50 */
51
52void _CORE_message_queue_Insert_message(
53  CORE_message_queue_Control        *the_message_queue,
54  CORE_message_queue_Buffer_control *the_message,
55  CORE_message_queue_Submit_types    submit_type
56)
57{
58  ISR_Level  level;
59  #if defined(RTEMS_SCORE_COREMSG_ENABLE_NOTIFICATION)
60    bool    notify = false;
61    #define SET_NOTIFY() \
62      if ( the_message_queue->number_of_pending_messages == 0 )
63        notify = true;
64  #else
65    #define SET_NOTIFY()
66  #endif
67
68  _CORE_message_queue_Set_message_priority( the_message, submit_type );
69
70  #if !defined(RTEMS_SCORE_COREMSG_ENABLE_MESSAGE_PRIORITY)
71    _ISR_Disable( level );
72      SET_NOTIFY();
73      the_message_queue->number_of_pending_messages++;
74      if ( submit_type == CORE_MESSAGE_QUEUE_SEND_REQUEST )
75        _CORE_message_queue_Append_unprotected(the_message_queue, the_message);
76      else
77        _CORE_message_queue_Prepend_unprotected(the_message_queue, the_message);
78    _ISR_Enable( level );
79  #else
80    if ( submit_type == CORE_MESSAGE_QUEUE_SEND_REQUEST ) {
81      _ISR_Disable( level );
82        SET_NOTIFY();
83        the_message_queue->number_of_pending_messages++;
84        _CORE_message_queue_Append_unprotected(the_message_queue, the_message);
85      _ISR_Enable( level );
86    } else if ( submit_type == CORE_MESSAGE_QUEUE_URGENT_REQUEST ) {
87      _ISR_Disable( level );
88        SET_NOTIFY();
89        the_message_queue->number_of_pending_messages++;
90        _CORE_message_queue_Prepend_unprotected(the_message_queue, the_message);
91      _ISR_Enable( level );
92    } else {
93      CORE_message_queue_Buffer_control *this_message;
94      Chain_Node                        *the_node;
95      Chain_Control                     *the_header;
96      int                                the_priority;
97
98      the_priority = _CORE_message_queue_Get_message_priority(the_message);
99      the_header = &the_message_queue->Pending_messages;
100      the_node = the_header->first;
101      while ( !_Chain_Is_tail( the_header, the_node ) ) {
102        int this_priority;
103
104        this_message = (CORE_message_queue_Buffer_control *) the_node;
105
106        this_priority = _CORE_message_queue_Get_message_priority(this_message);
107
108        if ( this_priority <= the_priority ) {
109          the_node = the_node->next;
110          continue;
111        }
112        break;
113      }
114      _ISR_Disable( level );
115        SET_NOTIFY();
116        the_message_queue->number_of_pending_messages++;
117        _Chain_Insert_unprotected( the_node->previous, &the_message->Node );
118      _ISR_Enable( level );
119    }
120  #endif
121
122  #if defined(RTEMS_SCORE_COREMSG_ENABLE_NOTIFICATION)
123    /*
124     *  According to POSIX, does this happen before or after the message
125     *  is actually enqueued.  It is logical to think afterwards, because
126     *  the message is actually in the queue at this point.
127     */
128    if ( notify && the_message_queue->notify_handler )
129      (*the_message_queue->notify_handler)(the_message_queue->notify_argument);
130  #endif
131}
Note: See TracBrowser for help on using the repository browser.