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-1999. |
---|
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.OARcorp.com/rtems/license.html. |
---|
16 | * |
---|
17 | * $Id$ |
---|
18 | */ |
---|
19 | |
---|
20 | #include <rtems/system.h> |
---|
21 | #include <rtems/score/chain.h> |
---|
22 | #include <rtems/score/isr.h> |
---|
23 | #include <rtems/score/object.h> |
---|
24 | #include <rtems/score/coremsg.h> |
---|
25 | #include <rtems/score/states.h> |
---|
26 | #include <rtems/score/thread.h> |
---|
27 | #include <rtems/score/wkspace.h> |
---|
28 | #if defined(RTEMS_MULTIPROCESSING) |
---|
29 | #include <rtems/score/mpci.h> |
---|
30 | #endif |
---|
31 | |
---|
32 | /*PAGE |
---|
33 | * |
---|
34 | * _CORE_message_queue_Insert_message |
---|
35 | * |
---|
36 | * This kernel routine inserts the specified message into the |
---|
37 | * message queue. It is assumed that the message has been filled |
---|
38 | * in before this routine is called. |
---|
39 | * |
---|
40 | * Input parameters: |
---|
41 | * the_message_queue - pointer to message queue |
---|
42 | * the_message - message to insert |
---|
43 | * priority - insert indication |
---|
44 | * |
---|
45 | * Output parameters: NONE |
---|
46 | * |
---|
47 | * INTERRUPT LATENCY: |
---|
48 | * insert |
---|
49 | */ |
---|
50 | |
---|
51 | void _CORE_message_queue_Insert_message( |
---|
52 | CORE_message_queue_Control *the_message_queue, |
---|
53 | CORE_message_queue_Buffer_control *the_message, |
---|
54 | CORE_message_queue_Submit_types submit_type |
---|
55 | ) |
---|
56 | { |
---|
57 | the_message_queue->number_of_pending_messages += 1; |
---|
58 | |
---|
59 | the_message->priority = submit_type; |
---|
60 | |
---|
61 | switch ( submit_type ) { |
---|
62 | case CORE_MESSAGE_QUEUE_SEND_REQUEST: |
---|
63 | _CORE_message_queue_Append( the_message_queue, the_message ); |
---|
64 | break; |
---|
65 | case CORE_MESSAGE_QUEUE_URGENT_REQUEST: |
---|
66 | _CORE_message_queue_Prepend( the_message_queue, the_message ); |
---|
67 | break; |
---|
68 | default: |
---|
69 | /* XXX interrupt critical section needs to be addressed */ |
---|
70 | { |
---|
71 | CORE_message_queue_Buffer_control *this_message; |
---|
72 | Chain_Node *the_node; |
---|
73 | Chain_Control *the_header; |
---|
74 | |
---|
75 | the_header = &the_message_queue->Pending_messages; |
---|
76 | the_node = the_header->first; |
---|
77 | while ( !_Chain_Is_tail( the_header, the_node ) ) { |
---|
78 | |
---|
79 | this_message = (CORE_message_queue_Buffer_control *) the_node; |
---|
80 | |
---|
81 | if ( this_message->priority <= the_message->priority ) { |
---|
82 | the_node = the_node->next; |
---|
83 | continue; |
---|
84 | } |
---|
85 | |
---|
86 | break; |
---|
87 | } |
---|
88 | _Chain_Insert( the_node->previous, &the_message->Node ); |
---|
89 | } |
---|
90 | break; |
---|
91 | } |
---|
92 | |
---|
93 | /* |
---|
94 | * According to POSIX, does this happen before or after the message |
---|
95 | * is actually enqueued. It is logical to think afterwards, because |
---|
96 | * the message is actually in the queue at this point. |
---|
97 | */ |
---|
98 | |
---|
99 | if ( the_message_queue->number_of_pending_messages == 1 && |
---|
100 | the_message_queue->notify_handler ) |
---|
101 | (*the_message_queue->notify_handler)( the_message_queue->notify_argument ); |
---|
102 | } |
---|