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

4.115
Last change on this file since fe6c170c was fe6c170c, checked in by Sebastian Huber <sebastian.huber@…>, on 07/24/13 at 14:19:52

score: Create states implementation header

Move implementation specific parts of states.h and states.inl into new
header file statesimpl.h. The states.h contains now only the
application visible API.

  • 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.com/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/object.h>
25#include <rtems/score/coremsgimpl.h>
26#include <rtems/score/thread.h>
27#include <rtems/score/wkspace.h>
28
29void _CORE_message_queue_Insert_message(
30  CORE_message_queue_Control        *the_message_queue,
31  CORE_message_queue_Buffer_control *the_message,
32  CORE_message_queue_Submit_types    submit_type
33)
34{
35  ISR_Level  level;
36  #if defined(RTEMS_SCORE_COREMSG_ENABLE_NOTIFICATION)
37    bool    notify = false;
38    #define SET_NOTIFY() \
39      do { \
40        if ( the_message_queue->number_of_pending_messages == 0 ) \
41          notify = true; \
42      } while (0)
43  #else
44    #define SET_NOTIFY()
45  #endif
46
47  _CORE_message_queue_Set_message_priority( the_message, submit_type );
48
49  #if !defined(RTEMS_SCORE_COREMSG_ENABLE_MESSAGE_PRIORITY)
50    _ISR_Disable( level );
51      SET_NOTIFY();
52      the_message_queue->number_of_pending_messages++;
53      if ( submit_type == CORE_MESSAGE_QUEUE_SEND_REQUEST )
54        _CORE_message_queue_Append_unprotected(the_message_queue, the_message);
55      else
56        _CORE_message_queue_Prepend_unprotected(the_message_queue, the_message);
57    _ISR_Enable( level );
58  #else
59    if ( submit_type == CORE_MESSAGE_QUEUE_SEND_REQUEST ) {
60      _ISR_Disable( level );
61        SET_NOTIFY();
62        the_message_queue->number_of_pending_messages++;
63        _CORE_message_queue_Append_unprotected(the_message_queue, the_message);
64      _ISR_Enable( level );
65    } else if ( submit_type == CORE_MESSAGE_QUEUE_URGENT_REQUEST ) {
66      _ISR_Disable( level );
67        SET_NOTIFY();
68        the_message_queue->number_of_pending_messages++;
69        _CORE_message_queue_Prepend_unprotected(the_message_queue, the_message);
70      _ISR_Enable( level );
71    } else {
72      CORE_message_queue_Buffer_control *this_message;
73      Chain_Node                        *the_node;
74      Chain_Control                     *the_header;
75      int                                the_priority;
76
77      the_priority = _CORE_message_queue_Get_message_priority(the_message);
78      the_header = &the_message_queue->Pending_messages;
79      the_node = _Chain_First( the_header );
80      while ( !_Chain_Is_tail( the_header, the_node ) ) {
81        int this_priority;
82
83        this_message = (CORE_message_queue_Buffer_control *) the_node;
84
85        this_priority = _CORE_message_queue_Get_message_priority(this_message);
86
87        if ( this_priority <= the_priority ) {
88          the_node = the_node->next;
89          continue;
90        }
91        break;
92      }
93      _ISR_Disable( level );
94        SET_NOTIFY();
95        the_message_queue->number_of_pending_messages++;
96        _Chain_Insert_unprotected( the_node->previous, &the_message->Node );
97      _ISR_Enable( level );
98    }
99  #endif
100
101  #if defined(RTEMS_SCORE_COREMSG_ENABLE_NOTIFICATION)
102    /*
103     *  According to POSIX, does this happen before or after the message
104     *  is actually enqueued.  It is logical to think afterwards, because
105     *  the message is actually in the queue at this point.
106     */
107    if ( notify && the_message_queue->notify_handler )
108      (*the_message_queue->notify_handler)(the_message_queue->notify_argument);
109  #endif
110}
Note: See TracBrowser for help on using the repository browser.