[ac7d5ef0] | 1 | /* |
---|
| 2 | * Message Queue Manager |
---|
| 3 | * |
---|
| 4 | * |
---|
[60b791ad] | 5 | * COPYRIGHT (c) 1989-1998. |
---|
[ac7d5ef0] | 6 | * On-Line Applications Research Corporation (OAR). |
---|
[03f2154e] | 7 | * Copyright assigned to U.S. Government, 1994. |
---|
[ac7d5ef0] | 8 | * |
---|
[98e4ebf5] | 9 | * The license and distribution terms for this file may be |
---|
| 10 | * found in the file LICENSE in this distribution or at |
---|
[03f2154e] | 11 | * http://www.OARcorp.com/rtems/license.html. |
---|
[ac7d5ef0] | 12 | * |
---|
| 13 | * $Id$ |
---|
| 14 | */ |
---|
| 15 | |
---|
| 16 | #include <rtems/system.h> |
---|
[5e9b32b] | 17 | #include <rtems/score/sysstate.h> |
---|
| 18 | #include <rtems/score/chain.h> |
---|
| 19 | #include <rtems/score/isr.h> |
---|
| 20 | #include <rtems/score/coremsg.h> |
---|
| 21 | #include <rtems/score/object.h> |
---|
| 22 | #include <rtems/score/states.h> |
---|
| 23 | #include <rtems/score/thread.h> |
---|
| 24 | #include <rtems/score/wkspace.h> |
---|
[97e2729d] | 25 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[5e9b32b] | 26 | #include <rtems/score/mpci.h> |
---|
[97e2729d] | 27 | #endif |
---|
[3652ad35] | 28 | #include <rtems/rtems/status.h> |
---|
| 29 | #include <rtems/rtems/attr.h> |
---|
| 30 | #include <rtems/rtems/message.h> |
---|
| 31 | #include <rtems/rtems/options.h> |
---|
| 32 | #include <rtems/rtems/support.h> |
---|
[ac7d5ef0] | 33 | |
---|
| 34 | /*PAGE |
---|
| 35 | * |
---|
| 36 | * _Message_queue_Manager_initialization |
---|
| 37 | * |
---|
| 38 | * This routine initializes all message queue manager related |
---|
| 39 | * data structures. |
---|
| 40 | * |
---|
| 41 | * Input parameters: |
---|
| 42 | * maximum_message_queues - number of message queues to initialize |
---|
| 43 | * |
---|
| 44 | * Output parameters: NONE |
---|
| 45 | */ |
---|
| 46 | |
---|
| 47 | void _Message_queue_Manager_initialization( |
---|
[3b438fa] | 48 | unsigned32 maximum_message_queues |
---|
[ac7d5ef0] | 49 | ) |
---|
| 50 | { |
---|
| 51 | _Objects_Initialize_information( |
---|
| 52 | &_Message_queue_Information, |
---|
[9863dbf] | 53 | OBJECTS_RTEMS_MESSAGE_QUEUES, |
---|
[ac7d5ef0] | 54 | TRUE, |
---|
| 55 | maximum_message_queues, |
---|
[3235ad9] | 56 | sizeof( Message_queue_Control ), |
---|
| 57 | FALSE, |
---|
[5250ff39] | 58 | RTEMS_MAXIMUM_NAME_LENGTH, |
---|
| 59 | FALSE |
---|
[ac7d5ef0] | 60 | ); |
---|
[3a4ae6c] | 61 | |
---|
| 62 | /* |
---|
| 63 | * Register the MP Process Packet routine. |
---|
| 64 | */ |
---|
| 65 | |
---|
[97e2729d] | 66 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[3a4ae6c] | 67 | _MPCI_Register_packet_processor( |
---|
| 68 | MP_PACKET_MESSAGE_QUEUE, |
---|
| 69 | _Message_queue_MP_Process_packet |
---|
| 70 | ); |
---|
[97e2729d] | 71 | #endif |
---|
[3a4ae6c] | 72 | |
---|
[3b438fa] | 73 | } |
---|
[ac7d5ef0] | 74 | |
---|
[3b438fa] | 75 | /*PAGE |
---|
| 76 | * |
---|
| 77 | * _Message_queue_Allocate |
---|
| 78 | * |
---|
| 79 | * Allocate a message queue and the space for its messages |
---|
[3652ad35] | 80 | * |
---|
| 81 | * Input parameters: |
---|
| 82 | * the_message_queue - the message queue to allocate message buffers |
---|
| 83 | * count - maximum message and reserved buffer count |
---|
| 84 | * max_message_size - maximum size of each message |
---|
| 85 | * |
---|
| 86 | * Output parameters: |
---|
| 87 | * the_message_queue - set if successful, NULL otherwise |
---|
[3b438fa] | 88 | */ |
---|
[ac7d5ef0] | 89 | |
---|
[3b438fa] | 90 | Message_queue_Control *_Message_queue_Allocate ( |
---|
[3652ad35] | 91 | unsigned32 count, |
---|
| 92 | unsigned32 max_message_size |
---|
[3b438fa] | 93 | ) |
---|
| 94 | { |
---|
[3652ad35] | 95 | return |
---|
| 96 | (Message_queue_Control *)_Objects_Allocate(&_Message_queue_Information); |
---|
[3b438fa] | 97 | |
---|
[ac7d5ef0] | 98 | } |
---|
| 99 | |
---|
| 100 | /*PAGE |
---|
| 101 | * |
---|
| 102 | * rtems_message_queue_create |
---|
| 103 | * |
---|
| 104 | * This directive creates a message queue by allocating and initializing |
---|
| 105 | * a message queue data structure. |
---|
| 106 | * |
---|
| 107 | * Input parameters: |
---|
[3652ad35] | 108 | * name - user defined queue name |
---|
| 109 | * count - maximum message and reserved buffer count |
---|
[3b438fa] | 110 | * max_message_size - maximum size of each message |
---|
[3652ad35] | 111 | * attribute_set - process method |
---|
| 112 | * id - pointer to queue |
---|
[ac7d5ef0] | 113 | * |
---|
| 114 | * Output parameters: |
---|
| 115 | * id - queue id |
---|
[c4808ca] | 116 | * RTEMS_SUCCESSFUL - if successful |
---|
[ac7d5ef0] | 117 | * error code - if unsuccessful |
---|
| 118 | */ |
---|
| 119 | |
---|
| 120 | rtems_status_code rtems_message_queue_create( |
---|
[3235ad9] | 121 | rtems_name name, |
---|
[ac7d5ef0] | 122 | unsigned32 count, |
---|
[3b438fa] | 123 | unsigned32 max_message_size, |
---|
| 124 | rtems_attribute attribute_set, |
---|
[ac7d5ef0] | 125 | Objects_Id *id |
---|
| 126 | ) |
---|
| 127 | { |
---|
| 128 | register Message_queue_Control *the_message_queue; |
---|
[3652ad35] | 129 | CORE_message_queue_Attributes the_message_queue_attributes; |
---|
[97e2729d] | 130 | void *handler; |
---|
| 131 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[3652ad35] | 132 | boolean is_global; |
---|
[97e2729d] | 133 | #endif |
---|
[ac7d5ef0] | 134 | |
---|
[3235ad9] | 135 | if ( !rtems_is_name_valid( name ) ) |
---|
[3a4ae6c] | 136 | return RTEMS_INVALID_NAME; |
---|
[ac7d5ef0] | 137 | |
---|
[97e2729d] | 138 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[3652ad35] | 139 | if ( (is_global = _Attributes_Is_global( attribute_set ) ) && |
---|
[3a4ae6c] | 140 | !_System_state_Is_multiprocessing ) |
---|
| 141 | return RTEMS_MP_NOT_CONFIGURED; |
---|
[97e2729d] | 142 | #endif |
---|
[ac7d5ef0] | 143 | |
---|
[3b438fa] | 144 | if (count == 0) |
---|
| 145 | return RTEMS_INVALID_NUMBER; |
---|
| 146 | |
---|
| 147 | if (max_message_size == 0) |
---|
| 148 | return RTEMS_INVALID_SIZE; |
---|
| 149 | |
---|
[97e2729d] | 150 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[3b438fa] | 151 | #if 1 |
---|
| 152 | /* |
---|
| 153 | * I am not 100% sure this should be an error. |
---|
| 154 | * It seems reasonable to create a que with a large max size, |
---|
| 155 | * and then just send smaller msgs from remote (or all) nodes. |
---|
| 156 | */ |
---|
| 157 | |
---|
[3652ad35] | 158 | if ( is_global && (_MPCI_table->maximum_packet_size < max_message_size) ) |
---|
| 159 | return RTEMS_INVALID_SIZE; |
---|
[97e2729d] | 160 | #endif |
---|
[3b438fa] | 161 | #endif |
---|
| 162 | |
---|
[ac7d5ef0] | 163 | _Thread_Disable_dispatch(); /* protects object pointer */ |
---|
| 164 | |
---|
[3652ad35] | 165 | the_message_queue = _Message_queue_Allocate( count, max_message_size ); |
---|
[ac7d5ef0] | 166 | |
---|
| 167 | if ( !the_message_queue ) { |
---|
| 168 | _Thread_Enable_dispatch(); |
---|
[3a4ae6c] | 169 | return RTEMS_TOO_MANY; |
---|
[ac7d5ef0] | 170 | } |
---|
| 171 | |
---|
[97e2729d] | 172 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[3652ad35] | 173 | if ( is_global && |
---|
| 174 | !( _Objects_MP_Allocate_and_open( &_Message_queue_Information, |
---|
| 175 | name, the_message_queue->Object.id, FALSE ) ) ) { |
---|
[ac7d5ef0] | 176 | _Message_queue_Free( the_message_queue ); |
---|
| 177 | _Thread_Enable_dispatch(); |
---|
[3b438fa] | 178 | return RTEMS_TOO_MANY; |
---|
[ac7d5ef0] | 179 | } |
---|
[97e2729d] | 180 | #endif |
---|
[ac7d5ef0] | 181 | |
---|
[3b438fa] | 182 | the_message_queue->attribute_set = attribute_set; |
---|
[ac7d5ef0] | 183 | |
---|
[3652ad35] | 184 | if (_Attributes_Is_priority( attribute_set ) ) |
---|
| 185 | the_message_queue_attributes.discipline = |
---|
| 186 | CORE_MESSAGE_QUEUE_DISCIPLINES_PRIORITY; |
---|
| 187 | else |
---|
| 188 | the_message_queue_attributes.discipline = |
---|
| 189 | CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO; |
---|
| 190 | |
---|
[97e2729d] | 191 | handler = NULL; |
---|
| 192 | #if defined(RTEMS_MULTIPROCESSING) |
---|
| 193 | handler = _Message_queue_MP_Send_extract_proxy; |
---|
| 194 | #endif |
---|
| 195 | |
---|
[3652ad35] | 196 | if ( ! _CORE_message_queue_Initialize( |
---|
| 197 | &the_message_queue->message_queue, |
---|
| 198 | OBJECTS_RTEMS_MESSAGE_QUEUES, |
---|
| 199 | &the_message_queue_attributes, |
---|
| 200 | count, |
---|
| 201 | max_message_size, |
---|
[97e2729d] | 202 | handler ) ) { |
---|
| 203 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[3652ad35] | 204 | if ( is_global ) |
---|
| 205 | _Objects_MP_Close( |
---|
| 206 | &_Message_queue_Information, the_message_queue->Object.id); |
---|
[97e2729d] | 207 | #endif |
---|
[ac7d5ef0] | 208 | |
---|
[3652ad35] | 209 | _Message_queue_Free( the_message_queue ); |
---|
| 210 | _Thread_Enable_dispatch(); |
---|
| 211 | return RTEMS_TOO_MANY; |
---|
| 212 | } |
---|
[ac7d5ef0] | 213 | |
---|
[3235ad9] | 214 | _Objects_Open( |
---|
| 215 | &_Message_queue_Information, |
---|
| 216 | &the_message_queue->Object, |
---|
| 217 | &name |
---|
| 218 | ); |
---|
[ac7d5ef0] | 219 | |
---|
| 220 | *id = the_message_queue->Object.id; |
---|
| 221 | |
---|
[97e2729d] | 222 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[3652ad35] | 223 | if ( is_global ) |
---|
[ac7d5ef0] | 224 | _Message_queue_MP_Send_process_packet( |
---|
| 225 | MESSAGE_QUEUE_MP_ANNOUNCE_CREATE, |
---|
| 226 | the_message_queue->Object.id, |
---|
| 227 | name, |
---|
| 228 | 0 |
---|
| 229 | ); |
---|
[97e2729d] | 230 | #endif |
---|
[ac7d5ef0] | 231 | |
---|
| 232 | _Thread_Enable_dispatch(); |
---|
[3a4ae6c] | 233 | return RTEMS_SUCCESSFUL; |
---|
[ac7d5ef0] | 234 | } |
---|
| 235 | |
---|
| 236 | /*PAGE |
---|
| 237 | * |
---|
| 238 | * rtems_message_queue_ident |
---|
| 239 | * |
---|
| 240 | * This directive returns the system ID associated with |
---|
| 241 | * the message queue name. |
---|
| 242 | * |
---|
| 243 | * Input parameters: |
---|
| 244 | * name - user defined message queue name |
---|
| 245 | * node - node(s) to be searched |
---|
| 246 | * id - pointer to message queue id |
---|
| 247 | * |
---|
| 248 | * Output parameters: |
---|
| 249 | * *id - message queue id |
---|
| 250 | * RTEMS_SUCCESSFUL - if successful |
---|
| 251 | * error code - if unsuccessful |
---|
| 252 | */ |
---|
| 253 | |
---|
| 254 | rtems_status_code rtems_message_queue_ident( |
---|
[3235ad9] | 255 | rtems_name name, |
---|
[ac7d5ef0] | 256 | unsigned32 node, |
---|
| 257 | Objects_Id *id |
---|
| 258 | ) |
---|
| 259 | { |
---|
[3a4ae6c] | 260 | Objects_Name_to_id_errors status; |
---|
| 261 | |
---|
| 262 | status = _Objects_Name_to_id( |
---|
[3235ad9] | 263 | &_Message_queue_Information, |
---|
| 264 | &name, |
---|
| 265 | node, |
---|
| 266 | id |
---|
| 267 | ); |
---|
[3a4ae6c] | 268 | |
---|
| 269 | return _Status_Object_name_errors_to_status[ status ]; |
---|
[ac7d5ef0] | 270 | } |
---|
| 271 | |
---|
| 272 | /*PAGE |
---|
| 273 | * |
---|
| 274 | * rtems_message_queue_delete |
---|
| 275 | * |
---|
| 276 | * This directive allows a thread to delete the message queue specified |
---|
| 277 | * by the given queue identifier. |
---|
| 278 | * |
---|
| 279 | * Input parameters: |
---|
| 280 | * id - queue id |
---|
| 281 | * |
---|
| 282 | * Output parameters: |
---|
| 283 | * RTEMS_SUCCESSFUL - if successful |
---|
| 284 | * error code - if unsuccessful |
---|
| 285 | */ |
---|
| 286 | |
---|
| 287 | rtems_status_code rtems_message_queue_delete( |
---|
| 288 | Objects_Id id |
---|
| 289 | ) |
---|
| 290 | { |
---|
| 291 | register Message_queue_Control *the_message_queue; |
---|
| 292 | Objects_Locations location; |
---|
| 293 | |
---|
| 294 | the_message_queue = _Message_queue_Get( id, &location ); |
---|
| 295 | switch ( location ) { |
---|
[97e2729d] | 296 | |
---|
[ac7d5ef0] | 297 | case OBJECTS_REMOTE: |
---|
[97e2729d] | 298 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[ac7d5ef0] | 299 | _Thread_Dispatch(); |
---|
[3a4ae6c] | 300 | return RTEMS_ILLEGAL_ON_REMOTE_OBJECT; |
---|
[97e2729d] | 301 | #endif |
---|
| 302 | |
---|
| 303 | case OBJECTS_ERROR: |
---|
| 304 | return RTEMS_INVALID_ID; |
---|
| 305 | |
---|
[ac7d5ef0] | 306 | case OBJECTS_LOCAL: |
---|
| 307 | _Objects_Close( &_Message_queue_Information, |
---|
| 308 | &the_message_queue->Object ); |
---|
| 309 | |
---|
[97e2729d] | 310 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[3652ad35] | 311 | _CORE_message_queue_Close( |
---|
| 312 | &the_message_queue->message_queue, |
---|
| 313 | _Message_queue_MP_Send_object_was_deleted, |
---|
| 314 | CORE_MESSAGE_QUEUE_STATUS_WAS_DELETED |
---|
| 315 | ); |
---|
[97e2729d] | 316 | #endif |
---|
[ac7d5ef0] | 317 | |
---|
| 318 | _Message_queue_Free( the_message_queue ); |
---|
| 319 | |
---|
[97e2729d] | 320 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[ac7d5ef0] | 321 | if ( _Attributes_Is_global( the_message_queue->attribute_set ) ) { |
---|
| 322 | _Objects_MP_Close( |
---|
| 323 | &_Message_queue_Information, |
---|
| 324 | the_message_queue->Object.id |
---|
| 325 | ); |
---|
| 326 | |
---|
| 327 | _Message_queue_MP_Send_process_packet( |
---|
| 328 | MESSAGE_QUEUE_MP_ANNOUNCE_DELETE, |
---|
| 329 | the_message_queue->Object.id, |
---|
| 330 | 0, /* Not used */ |
---|
[9863dbf] | 331 | 0 |
---|
[ac7d5ef0] | 332 | ); |
---|
| 333 | } |
---|
[97e2729d] | 334 | #endif |
---|
[ac7d5ef0] | 335 | |
---|
| 336 | _Thread_Enable_dispatch(); |
---|
[3a4ae6c] | 337 | return RTEMS_SUCCESSFUL; |
---|
[ac7d5ef0] | 338 | } |
---|
| 339 | |
---|
[3a4ae6c] | 340 | return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ |
---|
[ac7d5ef0] | 341 | } |
---|
| 342 | |
---|
| 343 | /*PAGE |
---|
| 344 | * |
---|
| 345 | * rtems_message_queue_send |
---|
| 346 | * |
---|
| 347 | * This routine implements the directives q_send. It sends a |
---|
| 348 | * message to the specified message queue. |
---|
| 349 | * |
---|
| 350 | * Input parameters: |
---|
| 351 | * id - pointer to message queue |
---|
| 352 | * buffer - pointer to message buffer |
---|
[3652ad35] | 353 | * size - size of message to sent urgently |
---|
[ac7d5ef0] | 354 | * |
---|
| 355 | * Output parameters: |
---|
| 356 | * RTEMS_SUCCESSFUL - if successful |
---|
| 357 | * error code - if unsuccessful |
---|
| 358 | */ |
---|
| 359 | |
---|
| 360 | rtems_status_code rtems_message_queue_send( |
---|
| 361 | Objects_Id id, |
---|
[3b438fa] | 362 | void *buffer, |
---|
| 363 | unsigned32 size |
---|
[ac7d5ef0] | 364 | ) |
---|
| 365 | { |
---|
[3652ad35] | 366 | return( _Message_queue_Submit(id, buffer, size, MESSAGE_QUEUE_SEND_REQUEST) ); |
---|
[ac7d5ef0] | 367 | } |
---|
| 368 | |
---|
| 369 | /*PAGE |
---|
| 370 | * |
---|
| 371 | * rtems_message_queue_urgent |
---|
| 372 | * |
---|
| 373 | * This routine implements the directives q_urgent. It urgents a |
---|
| 374 | * message to the specified message queue. |
---|
| 375 | * |
---|
| 376 | * Input parameters: |
---|
| 377 | * id - pointer to message queue |
---|
| 378 | * buffer - pointer to message buffer |
---|
[3652ad35] | 379 | * size - size of message to sent urgently |
---|
[ac7d5ef0] | 380 | * |
---|
| 381 | * Output parameters: |
---|
| 382 | * RTEMS_SUCCESSFUL - if successful |
---|
[3652ad35] | 383 | * error code - if unsuccessful |
---|
[ac7d5ef0] | 384 | */ |
---|
| 385 | |
---|
| 386 | rtems_status_code rtems_message_queue_urgent( |
---|
| 387 | Objects_Id id, |
---|
[3b438fa] | 388 | void *buffer, |
---|
| 389 | unsigned32 size |
---|
[ac7d5ef0] | 390 | ) |
---|
| 391 | { |
---|
[3652ad35] | 392 | return(_Message_queue_Submit(id, buffer, size, MESSAGE_QUEUE_URGENT_REQUEST)); |
---|
[ac7d5ef0] | 393 | } |
---|
| 394 | |
---|
| 395 | /*PAGE |
---|
| 396 | * |
---|
| 397 | * rtems_message_queue_broadcast |
---|
| 398 | * |
---|
| 399 | * This directive sends a message for every thread waiting on the queue |
---|
| 400 | * designated by id. |
---|
| 401 | * |
---|
| 402 | * Input parameters: |
---|
| 403 | * id - pointer to message queue |
---|
| 404 | * buffer - pointer to message buffer |
---|
[3652ad35] | 405 | * size - size of message to broadcast |
---|
[ac7d5ef0] | 406 | * count - pointer to area to store number of threads made ready |
---|
| 407 | * |
---|
| 408 | * Output parameters: |
---|
| 409 | * count - number of threads made ready |
---|
[3652ad35] | 410 | * RTEMS_SUCCESSFUL - if successful |
---|
[ac7d5ef0] | 411 | * error code - if unsuccessful |
---|
| 412 | */ |
---|
| 413 | |
---|
| 414 | rtems_status_code rtems_message_queue_broadcast( |
---|
| 415 | Objects_Id id, |
---|
| 416 | void *buffer, |
---|
[3b438fa] | 417 | unsigned32 size, |
---|
[ac7d5ef0] | 418 | unsigned32 *count |
---|
| 419 | ) |
---|
| 420 | { |
---|
| 421 | register Message_queue_Control *the_message_queue; |
---|
| 422 | Objects_Locations location; |
---|
[3652ad35] | 423 | CORE_message_queue_Status core_status; |
---|
[ac7d5ef0] | 424 | |
---|
| 425 | the_message_queue = _Message_queue_Get( id, &location ); |
---|
| 426 | switch ( location ) { |
---|
| 427 | case OBJECTS_REMOTE: |
---|
[97e2729d] | 428 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[ac7d5ef0] | 429 | _Thread_Executing->Wait.return_argument = count; |
---|
| 430 | |
---|
| 431 | return |
---|
| 432 | _Message_queue_MP_Send_request_packet( |
---|
| 433 | MESSAGE_QUEUE_MP_BROADCAST_REQUEST, |
---|
| 434 | id, |
---|
[3b438fa] | 435 | buffer, |
---|
| 436 | &size, |
---|
| 437 | 0, /* option_set not used */ |
---|
[ac7d5ef0] | 438 | MPCI_DEFAULT_TIMEOUT |
---|
| 439 | ); |
---|
[97e2729d] | 440 | #endif |
---|
| 441 | |
---|
| 442 | case OBJECTS_ERROR: |
---|
| 443 | return RTEMS_INVALID_ID; |
---|
[ac7d5ef0] | 444 | |
---|
| 445 | case OBJECTS_LOCAL: |
---|
[3652ad35] | 446 | core_status = _CORE_message_queue_Broadcast( |
---|
| 447 | &the_message_queue->message_queue, |
---|
| 448 | buffer, |
---|
| 449 | size, |
---|
| 450 | id, |
---|
[97e2729d] | 451 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[3652ad35] | 452 | _Message_queue_Core_message_queue_mp_support, |
---|
[97e2729d] | 453 | #else |
---|
| 454 | NULL, |
---|
| 455 | #endif |
---|
[3652ad35] | 456 | count |
---|
| 457 | ); |
---|
| 458 | |
---|
[ac7d5ef0] | 459 | _Thread_Enable_dispatch(); |
---|
[3652ad35] | 460 | return |
---|
| 461 | _Message_queue_Translate_core_message_queue_return_code( core_status ); |
---|
[ac7d5ef0] | 462 | |
---|
[3b438fa] | 463 | } |
---|
[3652ad35] | 464 | return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ |
---|
[ac7d5ef0] | 465 | } |
---|
| 466 | |
---|
| 467 | /*PAGE |
---|
| 468 | * |
---|
| 469 | * rtems_message_queue_receive |
---|
| 470 | * |
---|
| 471 | * This directive dequeues a message from the designated message queue |
---|
| 472 | * and copies it into the requesting thread's buffer. |
---|
| 473 | * |
---|
| 474 | * Input parameters: |
---|
| 475 | * id - queue id |
---|
| 476 | * buffer - pointer to message buffer |
---|
[3652ad35] | 477 | * size - size of message receive |
---|
[ac7d5ef0] | 478 | * option_set - options on receive |
---|
| 479 | * timeout - number of ticks to wait |
---|
| 480 | * |
---|
| 481 | * Output parameters: |
---|
| 482 | * RTEMS_SUCCESSFUL - if successful |
---|
[3652ad35] | 483 | * error code - if unsuccessful |
---|
[ac7d5ef0] | 484 | */ |
---|
| 485 | |
---|
| 486 | rtems_status_code rtems_message_queue_receive( |
---|
| 487 | Objects_Id id, |
---|
| 488 | void *buffer, |
---|
[3652ad35] | 489 | unsigned32 *size, |
---|
[ac7d5ef0] | 490 | unsigned32 option_set, |
---|
[3b438fa] | 491 | rtems_interval timeout |
---|
[ac7d5ef0] | 492 | ) |
---|
| 493 | { |
---|
| 494 | register Message_queue_Control *the_message_queue; |
---|
[3b438fa] | 495 | Objects_Locations location; |
---|
[3652ad35] | 496 | boolean wait; |
---|
[ac7d5ef0] | 497 | |
---|
| 498 | the_message_queue = _Message_queue_Get( id, &location ); |
---|
| 499 | switch ( location ) { |
---|
[3b438fa] | 500 | |
---|
[ac7d5ef0] | 501 | case OBJECTS_REMOTE: |
---|
[97e2729d] | 502 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[3b438fa] | 503 | return _Message_queue_MP_Send_request_packet( |
---|
[ac7d5ef0] | 504 | MESSAGE_QUEUE_MP_RECEIVE_REQUEST, |
---|
| 505 | id, |
---|
| 506 | buffer, |
---|
[3652ad35] | 507 | size, |
---|
[ac7d5ef0] | 508 | option_set, |
---|
| 509 | timeout |
---|
| 510 | ); |
---|
[97e2729d] | 511 | #endif |
---|
| 512 | |
---|
| 513 | case OBJECTS_ERROR: |
---|
| 514 | return RTEMS_INVALID_ID; |
---|
[ac7d5ef0] | 515 | |
---|
| 516 | case OBJECTS_LOCAL: |
---|
[3652ad35] | 517 | if ( _Options_Is_no_wait( option_set ) ) |
---|
| 518 | wait = FALSE; |
---|
| 519 | else |
---|
| 520 | wait = TRUE; |
---|
| 521 | |
---|
| 522 | _CORE_message_queue_Seize( |
---|
| 523 | &the_message_queue->message_queue, |
---|
| 524 | the_message_queue->Object.id, |
---|
| 525 | buffer, |
---|
| 526 | size, |
---|
| 527 | wait, |
---|
| 528 | timeout |
---|
| 529 | ); |
---|
[ac7d5ef0] | 530 | _Thread_Enable_dispatch(); |
---|
[3652ad35] | 531 | return( _Message_queue_Translate_core_message_queue_return_code( |
---|
| 532 | _Thread_Executing->Wait.return_code ) ); |
---|
| 533 | |
---|
[ac7d5ef0] | 534 | } |
---|
| 535 | |
---|
[3a4ae6c] | 536 | return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ |
---|
[ac7d5ef0] | 537 | } |
---|
| 538 | |
---|
| 539 | /*PAGE |
---|
| 540 | * |
---|
| 541 | * rtems_message_queue_flush |
---|
| 542 | * |
---|
| 543 | * This directive removes all pending messages from a queue and returns |
---|
| 544 | * the number of messages removed. If no messages were present then |
---|
| 545 | * a count of zero is returned. |
---|
| 546 | * |
---|
| 547 | * Input parameters: |
---|
| 548 | * id - queue id |
---|
| 549 | * count - return area for count |
---|
| 550 | * |
---|
| 551 | * Output parameters: |
---|
| 552 | * count - number of messages removed ( 0 = empty queue ) |
---|
| 553 | * RTEMS_SUCCESSFUL - if successful |
---|
| 554 | * error code - if unsuccessful |
---|
| 555 | */ |
---|
| 556 | |
---|
| 557 | rtems_status_code rtems_message_queue_flush( |
---|
| 558 | Objects_Id id, |
---|
| 559 | unsigned32 *count |
---|
| 560 | ) |
---|
| 561 | { |
---|
| 562 | register Message_queue_Control *the_message_queue; |
---|
| 563 | Objects_Locations location; |
---|
| 564 | |
---|
| 565 | the_message_queue = _Message_queue_Get( id, &location ); |
---|
| 566 | switch ( location ) { |
---|
| 567 | case OBJECTS_REMOTE: |
---|
[97e2729d] | 568 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[ac7d5ef0] | 569 | _Thread_Executing->Wait.return_argument = count; |
---|
| 570 | |
---|
| 571 | return |
---|
| 572 | _Message_queue_MP_Send_request_packet( |
---|
| 573 | MESSAGE_QUEUE_MP_FLUSH_REQUEST, |
---|
| 574 | id, |
---|
[3b438fa] | 575 | 0, /* buffer not used */ |
---|
[3652ad35] | 576 | 0, /* size */ |
---|
[3b438fa] | 577 | 0, /* option_set not used */ |
---|
[ac7d5ef0] | 578 | MPCI_DEFAULT_TIMEOUT |
---|
| 579 | ); |
---|
[97e2729d] | 580 | #endif |
---|
| 581 | |
---|
| 582 | case OBJECTS_ERROR: |
---|
| 583 | return RTEMS_INVALID_ID; |
---|
[ac7d5ef0] | 584 | |
---|
| 585 | case OBJECTS_LOCAL: |
---|
[3652ad35] | 586 | *count = _CORE_message_queue_Flush( &the_message_queue->message_queue ); |
---|
[ac7d5ef0] | 587 | _Thread_Enable_dispatch(); |
---|
[3a4ae6c] | 588 | return RTEMS_SUCCESSFUL; |
---|
[ac7d5ef0] | 589 | } |
---|
| 590 | |
---|
[3a4ae6c] | 591 | return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ |
---|
[ac7d5ef0] | 592 | } |
---|
| 593 | |
---|
[e7d8b58] | 594 | /*PAGE |
---|
| 595 | * |
---|
| 596 | * rtems_message_queue_get_number_pending |
---|
| 597 | * |
---|
| 598 | * This directive returns the number of messages pending. |
---|
| 599 | * |
---|
| 600 | * Input parameters: |
---|
| 601 | * id - queue id |
---|
| 602 | * count - return area for count |
---|
| 603 | * |
---|
| 604 | * Output parameters: |
---|
| 605 | * count - number of messages removed ( 0 = empty queue ) |
---|
| 606 | * RTEMS_SUCCESSFUL - if successful |
---|
| 607 | * error code - if unsuccessful |
---|
| 608 | */ |
---|
| 609 | |
---|
| 610 | rtems_status_code rtems_message_queue_get_number_pending( |
---|
| 611 | Objects_Id id, |
---|
| 612 | unsigned32 *count |
---|
| 613 | ) |
---|
| 614 | { |
---|
| 615 | register Message_queue_Control *the_message_queue; |
---|
| 616 | Objects_Locations location; |
---|
| 617 | |
---|
| 618 | the_message_queue = _Message_queue_Get( id, &location ); |
---|
| 619 | switch ( location ) { |
---|
| 620 | case OBJECTS_REMOTE: |
---|
[97e2729d] | 621 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[e7d8b58] | 622 | _Thread_Executing->Wait.return_argument = count; |
---|
| 623 | |
---|
[97e2729d] | 624 | return _Message_queue_MP_Send_request_packet( |
---|
[e7d8b58] | 625 | MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_REQUEST, |
---|
| 626 | id, |
---|
| 627 | 0, /* buffer not used */ |
---|
| 628 | 0, /* size */ |
---|
| 629 | 0, /* option_set not used */ |
---|
| 630 | MPCI_DEFAULT_TIMEOUT |
---|
| 631 | ); |
---|
[97e2729d] | 632 | #endif |
---|
| 633 | |
---|
| 634 | case OBJECTS_ERROR: |
---|
| 635 | return RTEMS_INVALID_ID; |
---|
[e7d8b58] | 636 | |
---|
| 637 | case OBJECTS_LOCAL: |
---|
| 638 | *count = the_message_queue->message_queue.number_of_pending_messages; |
---|
| 639 | _Thread_Enable_dispatch(); |
---|
| 640 | return RTEMS_SUCCESSFUL; |
---|
| 641 | } |
---|
| 642 | |
---|
| 643 | return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ |
---|
| 644 | } |
---|
| 645 | |
---|
[ac7d5ef0] | 646 | /*PAGE |
---|
| 647 | * |
---|
| 648 | * _Message_queue_Submit |
---|
| 649 | * |
---|
[3652ad35] | 650 | * This routine implements the directives rtems_message_queue_send |
---|
| 651 | * and rtems_message_queue_urgent. It processes a message that is |
---|
| 652 | * to be submitted to the designated message queue. The message will |
---|
| 653 | * either be processed as a send send message which it will be inserted |
---|
| 654 | * at the rear of the queue or it will be processed as an urgent message |
---|
| 655 | * which will be inserted at the front of the queue. |
---|
[ac7d5ef0] | 656 | * |
---|
| 657 | * Input parameters: |
---|
| 658 | * id - pointer to message queue |
---|
[3b438fa] | 659 | * buffer - pointer to message buffer |
---|
| 660 | * size - size in bytes of message to send |
---|
[ac7d5ef0] | 661 | * submit_type - send or urgent message |
---|
| 662 | * |
---|
| 663 | * Output parameters: |
---|
| 664 | * RTEMS_SUCCESSFUL - if successful |
---|
[3b438fa] | 665 | * error code - if unsuccessful |
---|
[ac7d5ef0] | 666 | */ |
---|
| 667 | |
---|
| 668 | rtems_status_code _Message_queue_Submit( |
---|
| 669 | Objects_Id id, |
---|
[3b438fa] | 670 | void *buffer, |
---|
| 671 | unsigned32 size, |
---|
[ac7d5ef0] | 672 | Message_queue_Submit_types submit_type |
---|
| 673 | ) |
---|
| 674 | { |
---|
[3652ad35] | 675 | register Message_queue_Control *the_message_queue; |
---|
| 676 | Objects_Locations location; |
---|
| 677 | CORE_message_queue_Status core_status; |
---|
[ac7d5ef0] | 678 | |
---|
| 679 | the_message_queue = _Message_queue_Get( id, &location ); |
---|
[3b438fa] | 680 | switch ( location ) |
---|
| 681 | { |
---|
[ac7d5ef0] | 682 | case OBJECTS_REMOTE: |
---|
[97e2729d] | 683 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[ac7d5ef0] | 684 | switch ( submit_type ) { |
---|
| 685 | case MESSAGE_QUEUE_SEND_REQUEST: |
---|
[97e2729d] | 686 | return _Message_queue_MP_Send_request_packet( |
---|
[ac7d5ef0] | 687 | MESSAGE_QUEUE_MP_SEND_REQUEST, |
---|
| 688 | id, |
---|
| 689 | buffer, |
---|
[3b438fa] | 690 | &size, |
---|
| 691 | 0, /* option_set */ |
---|
[ac7d5ef0] | 692 | MPCI_DEFAULT_TIMEOUT |
---|
| 693 | ); |
---|
| 694 | |
---|
| 695 | case MESSAGE_QUEUE_URGENT_REQUEST: |
---|
[97e2729d] | 696 | return _Message_queue_MP_Send_request_packet( |
---|
[ac7d5ef0] | 697 | MESSAGE_QUEUE_MP_URGENT_REQUEST, |
---|
| 698 | id, |
---|
| 699 | buffer, |
---|
[3b438fa] | 700 | &size, |
---|
| 701 | 0, /* option_set */ |
---|
[ac7d5ef0] | 702 | MPCI_DEFAULT_TIMEOUT |
---|
| 703 | ); |
---|
| 704 | } |
---|
[97e2729d] | 705 | break; |
---|
| 706 | #endif |
---|
| 707 | |
---|
| 708 | case OBJECTS_ERROR: |
---|
| 709 | return RTEMS_INVALID_ID; |
---|
[ac7d5ef0] | 710 | |
---|
[3b438fa] | 711 | case OBJECTS_LOCAL: |
---|
[ac7d5ef0] | 712 | switch ( submit_type ) { |
---|
| 713 | case MESSAGE_QUEUE_SEND_REQUEST: |
---|
[3652ad35] | 714 | core_status = _CORE_message_queue_Send( |
---|
| 715 | &the_message_queue->message_queue, |
---|
| 716 | buffer, |
---|
| 717 | size, |
---|
| 718 | id, |
---|
[97e2729d] | 719 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[3652ad35] | 720 | _Message_queue_Core_message_queue_mp_support |
---|
[97e2729d] | 721 | #else |
---|
| 722 | NULL |
---|
| 723 | #endif |
---|
[3652ad35] | 724 | ); |
---|
[ac7d5ef0] | 725 | break; |
---|
| 726 | case MESSAGE_QUEUE_URGENT_REQUEST: |
---|
[3652ad35] | 727 | core_status = _CORE_message_queue_Urgent( |
---|
| 728 | &the_message_queue->message_queue, |
---|
| 729 | buffer, |
---|
| 730 | size, |
---|
| 731 | id, |
---|
[97e2729d] | 732 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[3652ad35] | 733 | _Message_queue_Core_message_queue_mp_support |
---|
[97e2729d] | 734 | #else |
---|
| 735 | NULL |
---|
| 736 | #endif |
---|
[3652ad35] | 737 | ); |
---|
[ac7d5ef0] | 738 | break; |
---|
[3652ad35] | 739 | default: |
---|
| 740 | core_status = CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL; |
---|
| 741 | return RTEMS_INTERNAL_ERROR; /* should never get here */ |
---|
[ac7d5ef0] | 742 | } |
---|
| 743 | |
---|
| 744 | _Thread_Enable_dispatch(); |
---|
[3652ad35] | 745 | return _Message_queue_Translate_core_message_queue_return_code( |
---|
| 746 | core_status ); |
---|
[3b438fa] | 747 | |
---|
[ac7d5ef0] | 748 | } |
---|
[3652ad35] | 749 | return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ |
---|
| 750 | } |
---|
| 751 | |
---|
| 752 | /*PAGE |
---|
| 753 | * |
---|
| 754 | * _Message_queue_Translate_core_message_queue_return_code |
---|
| 755 | * |
---|
| 756 | * Input parameters: |
---|
| 757 | * the_message_queue_status - message_queue status code to translate |
---|
| 758 | * |
---|
| 759 | * Output parameters: |
---|
| 760 | * rtems status code - translated RTEMS status code |
---|
| 761 | * |
---|
| 762 | */ |
---|
| 763 | |
---|
| 764 | rtems_status_code _Message_queue_Translate_core_message_queue_return_code ( |
---|
| 765 | unsigned32 the_message_queue_status |
---|
| 766 | ) |
---|
| 767 | { |
---|
| 768 | switch ( the_message_queue_status ) { |
---|
| 769 | case CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL: |
---|
| 770 | return RTEMS_SUCCESSFUL; |
---|
| 771 | case CORE_MESSAGE_QUEUE_STATUS_INVALID_SIZE: |
---|
| 772 | return RTEMS_INVALID_SIZE; |
---|
| 773 | case CORE_MESSAGE_QUEUE_STATUS_TOO_MANY: |
---|
| 774 | return RTEMS_TOO_MANY; |
---|
| 775 | case CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED: |
---|
| 776 | return RTEMS_UNSATISFIED; |
---|
| 777 | case CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_NOWAIT: |
---|
| 778 | return RTEMS_UNSATISFIED; |
---|
| 779 | case CORE_MESSAGE_QUEUE_STATUS_WAS_DELETED: |
---|
| 780 | return RTEMS_OBJECT_WAS_DELETED; |
---|
| 781 | case CORE_MESSAGE_QUEUE_STATUS_TIMEOUT: |
---|
| 782 | return RTEMS_TIMEOUT; |
---|
| 783 | case THREAD_STATUS_PROXY_BLOCKING: |
---|
[ffe316d] | 784 | return RTEMS_PROXY_BLOCKING; |
---|
[3652ad35] | 785 | } |
---|
| 786 | _Internal_error_Occurred( /* XXX */ |
---|
| 787 | INTERNAL_ERROR_RTEMS_API, |
---|
| 788 | TRUE, |
---|
| 789 | the_message_queue_status |
---|
| 790 | ); |
---|
| 791 | return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ |
---|
| 792 | } |
---|
| 793 | |
---|
| 794 | /*PAGE |
---|
| 795 | * |
---|
| 796 | * _Message_queue_Core_message_queue_mp_support |
---|
| 797 | * |
---|
| 798 | * Input parameters: |
---|
| 799 | * the_thread - the remote thread the message was submitted to |
---|
| 800 | * id - id of the message queue |
---|
| 801 | * |
---|
| 802 | * Output parameters: NONE |
---|
| 803 | */ |
---|
| 804 | |
---|
[97e2729d] | 805 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[3652ad35] | 806 | void _Message_queue_Core_message_queue_mp_support ( |
---|
| 807 | Thread_Control *the_thread, |
---|
| 808 | Objects_Id id |
---|
| 809 | ) |
---|
| 810 | { |
---|
| 811 | the_thread->receive_packet->return_code = RTEMS_SUCCESSFUL; |
---|
| 812 | |
---|
| 813 | _Message_queue_MP_Send_response_packet( |
---|
| 814 | MESSAGE_QUEUE_MP_RECEIVE_RESPONSE, |
---|
| 815 | id, |
---|
| 816 | the_thread |
---|
| 817 | ); |
---|
[ac7d5ef0] | 818 | } |
---|
[97e2729d] | 819 | #endif |
---|