[d65c3768] | 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 | * |
---|
[2bbe78a2] | 10 | * COPYRIGHT (c) 1989-2005. |
---|
[d65c3768] | 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 |
---|
[dd687d97] | 15 | * http://www.rtems.com/license/LICENSE. |
---|
[d65c3768] | 16 | * |
---|
| 17 | * $Id$ |
---|
| 18 | */ |
---|
| 19 | |
---|
[a8eed23] | 20 | #if HAVE_CONFIG_H |
---|
| 21 | #include "config.h" |
---|
| 22 | #endif |
---|
| 23 | |
---|
[d65c3768] | 24 | #include <rtems/system.h> |
---|
| 25 | #include <rtems/score/chain.h> |
---|
| 26 | #include <rtems/score/isr.h> |
---|
| 27 | #include <rtems/score/object.h> |
---|
| 28 | #include <rtems/score/coremsg.h> |
---|
| 29 | #include <rtems/score/states.h> |
---|
| 30 | #include <rtems/score/thread.h> |
---|
| 31 | #include <rtems/score/wkspace.h> |
---|
| 32 | |
---|
| 33 | /*PAGE |
---|
| 34 | * |
---|
| 35 | * _CORE_message_queue_Insert_message |
---|
| 36 | * |
---|
| 37 | * This kernel routine inserts the specified message into the |
---|
| 38 | * message queue. It is assumed that the message has been filled |
---|
| 39 | * in before this routine is called. |
---|
| 40 | * |
---|
| 41 | * Input parameters: |
---|
| 42 | * the_message_queue - pointer to message queue |
---|
| 43 | * the_message - message to insert |
---|
| 44 | * priority - insert indication |
---|
| 45 | * |
---|
| 46 | * Output parameters: NONE |
---|
| 47 | * |
---|
| 48 | * INTERRUPT LATENCY: |
---|
| 49 | * insert |
---|
| 50 | */ |
---|
| 51 | |
---|
| 52 | void _CORE_message_queue_Insert_message( |
---|
| 53 | CORE_message_queue_Control *the_message_queue, |
---|
| 54 | CORE_message_queue_Buffer_control *the_message, |
---|
| 55 | CORE_message_queue_Submit_types submit_type |
---|
| 56 | ) |
---|
| 57 | { |
---|
[2bbe78a2] | 58 | ISR_Level level; |
---|
[484a769] | 59 | bool notify = false; |
---|
[d65c3768] | 60 | |
---|
| 61 | the_message->priority = submit_type; |
---|
| 62 | |
---|
| 63 | switch ( submit_type ) { |
---|
| 64 | case CORE_MESSAGE_QUEUE_SEND_REQUEST: |
---|
[2bbe78a2] | 65 | _ISR_Disable( level ); |
---|
| 66 | if ( the_message_queue->number_of_pending_messages++ == 0 ) |
---|
[484a769] | 67 | notify = true; |
---|
[2bbe78a2] | 68 | _CORE_message_queue_Append_unprotected(the_message_queue, the_message); |
---|
| 69 | _ISR_Enable( level ); |
---|
[d65c3768] | 70 | break; |
---|
| 71 | case CORE_MESSAGE_QUEUE_URGENT_REQUEST: |
---|
[2bbe78a2] | 72 | _ISR_Disable( level ); |
---|
| 73 | if ( the_message_queue->number_of_pending_messages++ == 0 ) |
---|
[484a769] | 74 | notify = true; |
---|
[2bbe78a2] | 75 | _CORE_message_queue_Prepend_unprotected(the_message_queue, the_message); |
---|
| 76 | _ISR_Enable( level ); |
---|
[d65c3768] | 77 | break; |
---|
| 78 | default: |
---|
| 79 | { |
---|
| 80 | CORE_message_queue_Buffer_control *this_message; |
---|
| 81 | Chain_Node *the_node; |
---|
| 82 | Chain_Control *the_header; |
---|
| 83 | |
---|
| 84 | the_header = &the_message_queue->Pending_messages; |
---|
| 85 | the_node = the_header->first; |
---|
| 86 | while ( !_Chain_Is_tail( the_header, the_node ) ) { |
---|
| 87 | |
---|
| 88 | this_message = (CORE_message_queue_Buffer_control *) the_node; |
---|
| 89 | |
---|
| 90 | if ( this_message->priority <= the_message->priority ) { |
---|
| 91 | the_node = the_node->next; |
---|
| 92 | continue; |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | break; |
---|
| 96 | } |
---|
[2bbe78a2] | 97 | _ISR_Disable( level ); |
---|
| 98 | if ( the_message_queue->number_of_pending_messages++ == 0 ) |
---|
[484a769] | 99 | notify = true; |
---|
[2bbe78a2] | 100 | _Chain_Insert_unprotected( the_node->previous, &the_message->Node ); |
---|
| 101 | _ISR_Enable( level ); |
---|
[d65c3768] | 102 | } |
---|
| 103 | break; |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | /* |
---|
| 107 | * According to POSIX, does this happen before or after the message |
---|
| 108 | * is actually enqueued. It is logical to think afterwards, because |
---|
| 109 | * the message is actually in the queue at this point. |
---|
| 110 | */ |
---|
| 111 | |
---|
[2bbe78a2] | 112 | if ( notify && the_message_queue->notify_handler ) |
---|
[d65c3768] | 113 | (*the_message_queue->notify_handler)( the_message_queue->notify_argument ); |
---|
| 114 | } |
---|