[c18e0ba] | 1 | /** |
---|
| 2 | * @file |
---|
[1e1b3e00] | 3 | * |
---|
[c18e0ba] | 4 | * @brief RTEMS Create Message Queue |
---|
| 5 | * @ingroup ClassicMessageQueue |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | /* |
---|
[3a638ce] | 9 | * COPYRIGHT (c) 1989-2014. |
---|
[1e1b3e00] | 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 |
---|
[c499856] | 14 | * http://www.rtems.org/license/LICENSE. |
---|
[1e1b3e00] | 15 | */ |
---|
| 16 | |
---|
[1095ec1] | 17 | #if HAVE_CONFIG_H |
---|
| 18 | #include "config.h" |
---|
| 19 | #endif |
---|
| 20 | |
---|
[21275b58] | 21 | #include <rtems/rtems/messageimpl.h> |
---|
| 22 | #include <rtems/rtems/status.h> |
---|
| 23 | #include <rtems/rtems/attrimpl.h> |
---|
| 24 | #include <rtems/rtems/options.h> |
---|
| 25 | #include <rtems/rtems/support.h> |
---|
[1e1b3e00] | 26 | #include <rtems/score/sysstate.h> |
---|
| 27 | #include <rtems/score/chain.h> |
---|
| 28 | #include <rtems/score/isr.h> |
---|
[b5d514f] | 29 | #include <rtems/score/coremsgimpl.h> |
---|
[1e1b3e00] | 30 | #include <rtems/score/thread.h> |
---|
| 31 | #include <rtems/score/wkspace.h> |
---|
[21275b58] | 32 | #include <rtems/sysinit.h> |
---|
[1e1b3e00] | 33 | |
---|
| 34 | rtems_status_code rtems_message_queue_create( |
---|
[d3b72ca3] | 35 | rtems_name name, |
---|
| 36 | uint32_t count, |
---|
| 37 | size_t max_message_size, |
---|
| 38 | rtems_attribute attribute_set, |
---|
| 39 | rtems_id *id |
---|
[1e1b3e00] | 40 | ) |
---|
| 41 | { |
---|
[3a638ce] | 42 | Message_queue_Control *the_message_queue; |
---|
[1e1a91ed] | 43 | CORE_message_queue_Disciplines discipline; |
---|
[1e1b3e00] | 44 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[484a769] | 45 | bool is_global; |
---|
[1e1b3e00] | 46 | #endif |
---|
| 47 | |
---|
| 48 | if ( !rtems_is_name_valid( name ) ) |
---|
| 49 | return RTEMS_INVALID_NAME; |
---|
| 50 | |
---|
[e980b219] | 51 | if ( !id ) |
---|
| 52 | return RTEMS_INVALID_ADDRESS; |
---|
| 53 | |
---|
[1e1b3e00] | 54 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[50f32b11] | 55 | if ( (is_global = _Attributes_Is_global( attribute_set ) ) && |
---|
[1e1b3e00] | 56 | !_System_state_Is_multiprocessing ) |
---|
| 57 | return RTEMS_MP_NOT_CONFIGURED; |
---|
| 58 | #endif |
---|
| 59 | |
---|
[53fb837a] | 60 | if ( count == 0 ) |
---|
[1e1b3e00] | 61 | return RTEMS_INVALID_NUMBER; |
---|
| 62 | |
---|
[53fb837a] | 63 | if ( max_message_size == 0 ) |
---|
[1e1b3e00] | 64 | return RTEMS_INVALID_SIZE; |
---|
| 65 | |
---|
| 66 | #if defined(RTEMS_MULTIPROCESSING) |
---|
| 67 | #if 1 |
---|
| 68 | /* |
---|
| 69 | * I am not 100% sure this should be an error. |
---|
| 70 | * It seems reasonable to create a que with a large max size, |
---|
| 71 | * and then just send smaller msgs from remote (or all) nodes. |
---|
| 72 | */ |
---|
[cf8a351] | 73 | if ( is_global ) { |
---|
| 74 | size_t max_packet_payload_size = _MPCI_table->maximum_packet_size |
---|
| 75 | - MESSAGE_QUEUE_MP_PACKET_SIZE; |
---|
[50f32b11] | 76 | |
---|
[cf8a351] | 77 | if ( max_message_size > max_packet_payload_size ) { |
---|
| 78 | return RTEMS_INVALID_SIZE; |
---|
| 79 | } |
---|
| 80 | } |
---|
[1e1b3e00] | 81 | #endif |
---|
| 82 | #endif |
---|
[50f32b11] | 83 | |
---|
[f773c012] | 84 | the_message_queue = _Message_queue_Allocate(); |
---|
[1e1b3e00] | 85 | |
---|
| 86 | if ( !the_message_queue ) { |
---|
[23fec9f0] | 87 | _Objects_Allocator_unlock(); |
---|
[1e1b3e00] | 88 | return RTEMS_TOO_MANY; |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | #if defined(RTEMS_MULTIPROCESSING) |
---|
| 92 | if ( is_global && |
---|
| 93 | !( _Objects_MP_Allocate_and_open( &_Message_queue_Information, |
---|
[eaef4657] | 94 | name, the_message_queue->Object.id, false ) ) ) { |
---|
[1e1b3e00] | 95 | _Message_queue_Free( the_message_queue ); |
---|
[23fec9f0] | 96 | _Objects_Allocator_unlock(); |
---|
[1e1b3e00] | 97 | return RTEMS_TOO_MANY; |
---|
| 98 | } |
---|
| 99 | #endif |
---|
| 100 | |
---|
| 101 | the_message_queue->attribute_set = attribute_set; |
---|
| 102 | |
---|
| 103 | if (_Attributes_Is_priority( attribute_set ) ) |
---|
[1e1a91ed] | 104 | discipline = CORE_MESSAGE_QUEUE_DISCIPLINES_PRIORITY; |
---|
[1e1b3e00] | 105 | else |
---|
[1e1a91ed] | 106 | discipline = CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO; |
---|
[1e1b3e00] | 107 | |
---|
| 108 | if ( ! _CORE_message_queue_Initialize( |
---|
| 109 | &the_message_queue->message_queue, |
---|
[1e1a91ed] | 110 | discipline, |
---|
[1e1b3e00] | 111 | count, |
---|
[90015e7f] | 112 | max_message_size |
---|
| 113 | ) ) { |
---|
[1e1b3e00] | 114 | #if defined(RTEMS_MULTIPROCESSING) |
---|
| 115 | if ( is_global ) |
---|
| 116 | _Objects_MP_Close( |
---|
| 117 | &_Message_queue_Information, the_message_queue->Object.id); |
---|
| 118 | #endif |
---|
| 119 | |
---|
| 120 | _Message_queue_Free( the_message_queue ); |
---|
[23fec9f0] | 121 | _Objects_Allocator_unlock(); |
---|
[9120e88] | 122 | return RTEMS_UNSATISFIED; |
---|
[1e1b3e00] | 123 | } |
---|
| 124 | |
---|
| 125 | _Objects_Open( |
---|
| 126 | &_Message_queue_Information, |
---|
| 127 | &the_message_queue->Object, |
---|
[6312db3] | 128 | (Objects_Name) name |
---|
[1e1b3e00] | 129 | ); |
---|
| 130 | |
---|
| 131 | *id = the_message_queue->Object.id; |
---|
| 132 | |
---|
| 133 | #if defined(RTEMS_MULTIPROCESSING) |
---|
| 134 | if ( is_global ) |
---|
| 135 | _Message_queue_MP_Send_process_packet( |
---|
| 136 | MESSAGE_QUEUE_MP_ANNOUNCE_CREATE, |
---|
| 137 | the_message_queue->Object.id, |
---|
| 138 | name, |
---|
| 139 | 0 |
---|
| 140 | ); |
---|
| 141 | #endif |
---|
| 142 | |
---|
[23fec9f0] | 143 | _Objects_Allocator_unlock(); |
---|
[1e1b3e00] | 144 | return RTEMS_SUCCESSFUL; |
---|
| 145 | } |
---|
[21275b58] | 146 | |
---|
| 147 | static void _Message_queue_Manager_initialization(void) |
---|
| 148 | { |
---|
| 149 | _Objects_Initialize_information( &_Message_queue_Information); |
---|
| 150 | |
---|
| 151 | /* |
---|
| 152 | * Register the MP Process Packet routine. |
---|
| 153 | */ |
---|
| 154 | |
---|
| 155 | #if defined(RTEMS_MULTIPROCESSING) |
---|
| 156 | _MPCI_Register_packet_processor( |
---|
| 157 | MP_PACKET_MESSAGE_QUEUE, |
---|
| 158 | _Message_queue_MP_Process_packet |
---|
| 159 | ); |
---|
| 160 | #endif |
---|
| 161 | |
---|
| 162 | } |
---|
| 163 | |
---|
| 164 | RTEMS_SYSINIT_ITEM( |
---|
| 165 | _Message_queue_Manager_initialization, |
---|
| 166 | RTEMS_SYSINIT_CLASSIC_MESSAGE_QUEUE, |
---|
| 167 | RTEMS_SYSINIT_ORDER_MIDDLE |
---|
| 168 | ); |
---|