[e655f7e] | 1 | /** |
---|
| 2 | * @file |
---|
[82cb78d8] | 3 | * |
---|
[e655f7e] | 4 | * @brief Broadcast a Message to the Message Queue |
---|
| 5 | * @ingroup ScoreMessageQueue |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | /* |
---|
[7cb46943] | 9 | * COPYRIGHT (c) 1989-2008. |
---|
[82cb78d8] | 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. |
---|
[82cb78d8] | 15 | */ |
---|
| 16 | |
---|
[a8eed23] | 17 | #if HAVE_CONFIG_H |
---|
| 18 | #include "config.h" |
---|
| 19 | #endif |
---|
| 20 | |
---|
[b5d514f] | 21 | #include <rtems/score/coremsgimpl.h> |
---|
[a2e3f33] | 22 | #include <rtems/score/objectimpl.h> |
---|
[82cb78d8] | 23 | #include <rtems/score/thread.h> |
---|
| 24 | |
---|
| 25 | CORE_message_queue_Status _CORE_message_queue_Broadcast( |
---|
| 26 | CORE_message_queue_Control *the_message_queue, |
---|
[f773c012] | 27 | const void *buffer, |
---|
[32e101b] | 28 | size_t size, |
---|
[939ba81] | 29 | #if defined(RTEMS_MULTIPROCESSING) |
---|
| 30 | Objects_Id id, |
---|
| 31 | CORE_message_queue_API_mp_support_callout api_message_queue_mp_support, |
---|
| 32 | #else |
---|
| 33 | Objects_Id id __attribute__((unused)), |
---|
| 34 | CORE_message_queue_API_mp_support_callout api_message_queue_mp_support __attribute__((unused)), |
---|
| 35 | #endif |
---|
[3127180] | 36 | uint32_t *count |
---|
[82cb78d8] | 37 | ) |
---|
| 38 | { |
---|
| 39 | Thread_Control *the_thread; |
---|
[3127180] | 40 | uint32_t number_broadcasted; |
---|
[82cb78d8] | 41 | Thread_Wait_information *waitp; |
---|
[7cb46943] | 42 | |
---|
| 43 | if ( size > the_message_queue->maximum_message_size ) { |
---|
| 44 | return CORE_MESSAGE_QUEUE_STATUS_INVALID_SIZE; |
---|
| 45 | } |
---|
[82cb78d8] | 46 | |
---|
[53fb837a] | 47 | /* |
---|
| 48 | * If there are pending messages, then there can't be threads |
---|
| 49 | * waiting for us to send them a message. |
---|
| 50 | * |
---|
| 51 | * NOTE: This check is critical because threads can block on |
---|
| 52 | * send and receive and this ensures that we are broadcasting |
---|
| 53 | * the message to threads waiting to receive -- not to send. |
---|
| 54 | */ |
---|
| 55 | |
---|
| 56 | if ( the_message_queue->number_of_pending_messages != 0 ) { |
---|
| 57 | *count = 0; |
---|
| 58 | return CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL; |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | /* |
---|
| 62 | * There must be no pending messages if there is a thread waiting to |
---|
| 63 | * receive a message. |
---|
| 64 | */ |
---|
[82cb78d8] | 65 | number_broadcasted = 0; |
---|
[939ba81] | 66 | while ((the_thread = |
---|
[039cb994] | 67 | _Thread_queue_Dequeue(&the_message_queue->Wait_queue))) { |
---|
[82cb78d8] | 68 | waitp = &the_thread->Wait; |
---|
| 69 | number_broadcasted += 1; |
---|
| 70 | |
---|
| 71 | _CORE_message_queue_Copy_buffer( |
---|
| 72 | buffer, |
---|
[f773c012] | 73 | waitp->return_argument_second.mutable_object, |
---|
[7cb46943] | 74 | size |
---|
[82cb78d8] | 75 | ); |
---|
| 76 | |
---|
[f773c012] | 77 | *(size_t *) the_thread->Wait.return_argument = size; |
---|
[82cb78d8] | 78 | |
---|
[939ba81] | 79 | #if defined(RTEMS_MULTIPROCESSING) |
---|
| 80 | if ( !_Objects_Is_local_id( the_thread->Object.id ) ) |
---|
| 81 | (*api_message_queue_mp_support) ( the_thread, id ); |
---|
| 82 | #endif |
---|
[82cb78d8] | 83 | |
---|
| 84 | } |
---|
| 85 | *count = number_broadcasted; |
---|
| 86 | return CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL; |
---|
| 87 | } |
---|