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