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

4.115
Last change on this file since 25f5730f was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

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

  • Property mode set to 100644
File size: 3.5 KB
RevLine 
[f7f1d77]1/**
2 * @file
[d65c3768]3 *
[f7f1d77]4 * @brief Insert a Message into the Message Queue
5 * @ingroup ScoreMessageQueue
6 */
7
8/*
[2bbe78a2]9 *  COPYRIGHT (c) 1989-2005.
[d65c3768]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
[c499856]14 *  http://www.rtems.org/license/LICENSE.
[d65c3768]15 */
16
[a8eed23]17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
[d65c3768]21#include <rtems/system.h>
22#include <rtems/score/chain.h>
23#include <rtems/score/isr.h>
[b5d514f]24#include <rtems/score/coremsgimpl.h>
[d65c3768]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{
[2bbe78a2]34  ISR_Level  level;
[507d382]35  #if defined(RTEMS_SCORE_COREMSG_ENABLE_NOTIFICATION)
36    bool    notify = false;
37    #define SET_NOTIFY() \
[f8b7c83d]38      do { \
[49460dc]39        if ( the_message_queue->number_of_pending_messages == 0 ) \
[f8b7c83d]40          notify = true; \
41      } while (0)
[507d382]42  #else
43    #define SET_NOTIFY()
44  #endif
[d65c3768]45
[939ba81]46  _CORE_message_queue_Set_message_priority( the_message, submit_type );
[d65c3768]47
[507d382]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 ) {
[2bbe78a2]59      _ISR_Disable( level );
[507d382]60        SET_NOTIFY();
61        the_message_queue->number_of_pending_messages++;
[2bbe78a2]62        _CORE_message_queue_Append_unprotected(the_message_queue, the_message);
63      _ISR_Enable( level );
[507d382]64    } else if ( submit_type == CORE_MESSAGE_QUEUE_URGENT_REQUEST ) {
[2bbe78a2]65      _ISR_Disable( level );
[507d382]66        SET_NOTIFY();
67        the_message_queue->number_of_pending_messages++;
[2bbe78a2]68        _CORE_message_queue_Prepend_unprotected(the_message_queue, the_message);
69      _ISR_Enable( level );
[507d382]70    } else {
71      CORE_message_queue_Buffer_control *this_message;
72      Chain_Node                        *the_node;
73      Chain_Control                     *the_header;
[939ba81]74      int                                the_priority;
[d65c3768]75
[939ba81]76      the_priority = _CORE_message_queue_Get_message_priority(the_message);
[507d382]77      the_header = &the_message_queue->Pending_messages;
[ce002b16]78      the_node = _Chain_First( the_header );
[507d382]79      while ( !_Chain_Is_tail( the_header, the_node ) ) {
[939ba81]80        int this_priority;
[d65c3768]81
[507d382]82        this_message = (CORE_message_queue_Buffer_control *) the_node;
[d65c3768]83
[939ba81]84        this_priority = _CORE_message_queue_Get_message_priority(this_message);
85
86        if ( this_priority <= the_priority ) {
[507d382]87          the_node = the_node->next;
88          continue;
[d65c3768]89        }
[507d382]90        break;
[d65c3768]91      }
[507d382]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
[d65c3768]99
[507d382]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
[d65c3768]109}
Note: See TracBrowser for help on using the repository browser.