blob: 28407bae9847ac863d9ac41b48897d107e9a99f4 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
/**
* @file
*
* @brief Insert a Message into the Message Queue
* @ingroup ScoreMessageQueue
*/
/*
* COPYRIGHT (c) 1989-2005.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.org/license/LICENSE.
*/
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <rtems/score/coremsgimpl.h>
#include <rtems/score/isrlevel.h>
#if defined(RTEMS_SCORE_COREMSG_ENABLE_MESSAGE_PRIORITY)
static bool _CORE_message_queue_Order(
const Chain_Node *left,
const Chain_Node *right
)
{
const CORE_message_queue_Buffer_control *left_message;
const CORE_message_queue_Buffer_control *right_message;
left_message = (const CORE_message_queue_Buffer_control *) left;
right_message = (const CORE_message_queue_Buffer_control *) right;
return _CORE_message_queue_Get_message_priority( left_message ) <
_CORE_message_queue_Get_message_priority( right_message );
}
#endif
void _CORE_message_queue_Insert_message(
CORE_message_queue_Control *the_message_queue,
CORE_message_queue_Buffer_control *the_message,
CORE_message_queue_Submit_types submit_type
)
{
Chain_Control *pending_messages;
ISR_Level level;
#if defined(RTEMS_SCORE_COREMSG_ENABLE_NOTIFICATION)
bool notify;
#endif
_CORE_message_queue_Set_message_priority( the_message, submit_type );
pending_messages = &the_message_queue->Pending_messages;
_ISR_Disable( level );
#if defined(RTEMS_SCORE_COREMSG_ENABLE_NOTIFICATION)
notify = ( the_message_queue->number_of_pending_messages == 0 );
#endif
++the_message_queue->number_of_pending_messages;
if ( submit_type == CORE_MESSAGE_QUEUE_SEND_REQUEST ) {
_Chain_Append_unprotected( pending_messages, &the_message->Node );
#if defined(RTEMS_SCORE_COREMSG_ENABLE_MESSAGE_PRIORITY)
} else if ( submit_type != CORE_MESSAGE_QUEUE_URGENT_REQUEST ) {
_Chain_Insert_ordered_unprotected(
pending_messages,
&the_message->Node,
_CORE_message_queue_Order
);
#endif
} else {
_Chain_Prepend_unprotected( pending_messages, &the_message->Node );
}
_ISR_Enable( level );
#if defined(RTEMS_SCORE_COREMSG_ENABLE_NOTIFICATION)
/*
* According to POSIX, does this happen before or after the message
* is actually enqueued. It is logical to think afterwards, because
* the message is actually in the queue at this point.
*/
if ( notify && the_message_queue->notify_handler )
(*the_message_queue->notify_handler)(the_message_queue->notify_argument);
#endif
}
|