source: rtems/cpukit/score/src/coremsginsert.c @ bd029d87

4.8
Last change on this file since bd029d87 was 2bbe78a2, checked in by Joel Sherrill <joel.sherrill@…>, on 09/01/05 at 16:32:06

2005-09-01 Joel Sherrill <joel@…>

PR 820/rtems

  • score/inline/rtems/score/coremsg.inl, score/macros/rtems/score/coremsg.inl, score/src/coremsginsert.c: Increment of pending message count should be atomic with insertion on the pending message chain. Determination of the need to call the notification handler should also be in this atomic section of code.
  • Property mode set to 100644
File size: 3.4 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#if defined(RTEMS_MULTIPROCESSING)
33#include <rtems/score/mpci.h>
34#endif
35
36/*PAGE
37 *
38 *  _CORE_message_queue_Insert_message
39 *
40 *  This kernel routine inserts the specified message into the
41 *  message queue.  It is assumed that the message has been filled
42 *  in before this routine is called.
43 *
44 *  Input parameters:
45 *    the_message_queue - pointer to message queue
46 *    the_message       - message to insert
47 *    priority          - insert indication
48 *
49 *  Output parameters:  NONE
50 *
51 *  INTERRUPT LATENCY:
52 *    insert
53 */
54
55void _CORE_message_queue_Insert_message(
56  CORE_message_queue_Control        *the_message_queue,
57  CORE_message_queue_Buffer_control *the_message,
58  CORE_message_queue_Submit_types    submit_type
59)
60{
61  ISR_Level  level;
62  boolean    notify = FALSE;
63
64  the_message->priority = submit_type;
65
66  switch ( submit_type ) {
67    case CORE_MESSAGE_QUEUE_SEND_REQUEST:
68      _ISR_Disable( level );
69        if ( the_message_queue->number_of_pending_messages++ == 0 )
70          notify = TRUE;
71        _CORE_message_queue_Append_unprotected(the_message_queue, the_message);
72      _ISR_Enable( level );
73      break;
74    case CORE_MESSAGE_QUEUE_URGENT_REQUEST:
75      _ISR_Disable( level );
76        if ( the_message_queue->number_of_pending_messages++ == 0 )
77          notify = TRUE;
78        _CORE_message_queue_Prepend_unprotected(the_message_queue, the_message);
79      _ISR_Enable( level );
80      break;
81    default:
82      {
83        CORE_message_queue_Buffer_control *this_message;
84        Chain_Node                        *the_node;
85        Chain_Control                     *the_header;
86
87        the_header = &the_message_queue->Pending_messages;
88        the_node = the_header->first;
89        while ( !_Chain_Is_tail( the_header, the_node ) ) {
90
91          this_message = (CORE_message_queue_Buffer_control *) the_node;
92
93          if ( this_message->priority <= the_message->priority ) {
94            the_node = the_node->next;
95            continue;
96          }
97
98          break;
99        }
100        _ISR_Disable( level );
101          if ( the_message_queue->number_of_pending_messages++ == 0 )
102            notify = TRUE;
103          _Chain_Insert_unprotected( the_node->previous, &the_message->Node );
104        _ISR_Enable( level );
105      }
106      break;
107  }
108
109  /*
110   *  According to POSIX, does this happen before or after the message
111   *  is actually enqueued.  It is logical to think afterwards, because
112   *  the message is actually in the queue at this point.
113   */
114
115  if ( notify && the_message_queue->notify_handler )
116    (*the_message_queue->notify_handler)( the_message_queue->notify_argument );
117}
Note: See TracBrowser for help on using the repository browser.