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.org/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #if HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <rtems/score/coremsgimpl.h> |
---|
22 | |
---|
23 | #if defined(RTEMS_SCORE_COREMSG_ENABLE_MESSAGE_PRIORITY) |
---|
24 | static bool _CORE_message_queue_Order( |
---|
25 | const Chain_Node *left, |
---|
26 | const Chain_Node *right |
---|
27 | ) |
---|
28 | { |
---|
29 | const CORE_message_queue_Buffer_control *left_message; |
---|
30 | const CORE_message_queue_Buffer_control *right_message; |
---|
31 | |
---|
32 | left_message = (const CORE_message_queue_Buffer_control *) left; |
---|
33 | right_message = (const CORE_message_queue_Buffer_control *) right; |
---|
34 | |
---|
35 | return _CORE_message_queue_Get_message_priority( left_message ) < |
---|
36 | _CORE_message_queue_Get_message_priority( right_message ); |
---|
37 | } |
---|
38 | #endif |
---|
39 | |
---|
40 | void _CORE_message_queue_Insert_message( |
---|
41 | CORE_message_queue_Control *the_message_queue, |
---|
42 | CORE_message_queue_Buffer_control *the_message, |
---|
43 | const void *content_source, |
---|
44 | size_t content_size, |
---|
45 | CORE_message_queue_Submit_types submit_type |
---|
46 | ) |
---|
47 | { |
---|
48 | Chain_Control *pending_messages; |
---|
49 | #if defined(RTEMS_SCORE_COREMSG_ENABLE_NOTIFICATION) |
---|
50 | bool notify; |
---|
51 | #endif |
---|
52 | |
---|
53 | the_message->Contents.size = content_size; |
---|
54 | |
---|
55 | _CORE_message_queue_Copy_buffer( |
---|
56 | content_source, |
---|
57 | the_message->Contents.buffer, |
---|
58 | content_size |
---|
59 | ); |
---|
60 | |
---|
61 | #if defined(RTEMS_SCORE_COREMSG_ENABLE_MESSAGE_PRIORITY) |
---|
62 | the_message->priority = submit_type; |
---|
63 | #endif |
---|
64 | |
---|
65 | pending_messages = &the_message_queue->Pending_messages; |
---|
66 | |
---|
67 | #if defined(RTEMS_SCORE_COREMSG_ENABLE_NOTIFICATION) |
---|
68 | notify = ( the_message_queue->number_of_pending_messages == 0 ); |
---|
69 | #endif |
---|
70 | ++the_message_queue->number_of_pending_messages; |
---|
71 | |
---|
72 | if ( submit_type == CORE_MESSAGE_QUEUE_SEND_REQUEST ) { |
---|
73 | _Chain_Append_unprotected( pending_messages, &the_message->Node ); |
---|
74 | #if defined(RTEMS_SCORE_COREMSG_ENABLE_MESSAGE_PRIORITY) |
---|
75 | } else if ( submit_type != CORE_MESSAGE_QUEUE_URGENT_REQUEST ) { |
---|
76 | _Chain_Insert_ordered_unprotected( |
---|
77 | pending_messages, |
---|
78 | &the_message->Node, |
---|
79 | _CORE_message_queue_Order |
---|
80 | ); |
---|
81 | #endif |
---|
82 | } else { |
---|
83 | _Chain_Prepend_unprotected( pending_messages, &the_message->Node ); |
---|
84 | } |
---|
85 | |
---|
86 | #if defined(RTEMS_SCORE_COREMSG_ENABLE_NOTIFICATION) |
---|
87 | /* |
---|
88 | * According to POSIX, does this happen before or after the message |
---|
89 | * is actually enqueued. It is logical to think afterwards, because |
---|
90 | * the message is actually in the queue at this point. |
---|
91 | */ |
---|
92 | if ( notify && the_message_queue->notify_handler ) |
---|
93 | (*the_message_queue->notify_handler)(the_message_queue->notify_argument); |
---|
94 | #endif |
---|
95 | } |
---|