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 | * |
---|
10 | * COPYRIGHT (c) 1989-2008. |
---|
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 |
---|
15 | * http://www.rtems.com/license/LICENSE. |
---|
16 | * |
---|
17 | * $Id$ |
---|
18 | */ |
---|
19 | |
---|
20 | #if HAVE_CONFIG_H |
---|
21 | #include "config.h" |
---|
22 | #endif |
---|
23 | |
---|
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_Broadcast |
---|
36 | * |
---|
37 | * This function sends a message for every thread waiting on the queue and |
---|
38 | * returns the number of threads made ready by the message. |
---|
39 | * |
---|
40 | * Input parameters: |
---|
41 | * the_message_queue - message is submitted to this message queue |
---|
42 | * buffer - pointer to message buffer |
---|
43 | * size - size in bytes of message to send |
---|
44 | * id - id of message queue |
---|
45 | * api_message_queue_mp_support - api specific mp support callout |
---|
46 | * count - area to store number of threads made ready |
---|
47 | * |
---|
48 | * Output parameters: |
---|
49 | * count - number of threads made ready |
---|
50 | * CORE_MESSAGE_QUEUE_SUCCESSFUL - if successful |
---|
51 | * error code - if unsuccessful |
---|
52 | */ |
---|
53 | |
---|
54 | CORE_message_queue_Status _CORE_message_queue_Broadcast( |
---|
55 | CORE_message_queue_Control *the_message_queue, |
---|
56 | const void *buffer, |
---|
57 | size_t size, |
---|
58 | #if defined(RTEMS_MULTIPROCESSING) |
---|
59 | Objects_Id id, |
---|
60 | CORE_message_queue_API_mp_support_callout api_message_queue_mp_support, |
---|
61 | #else |
---|
62 | Objects_Id id __attribute__((unused)), |
---|
63 | CORE_message_queue_API_mp_support_callout api_message_queue_mp_support __attribute__((unused)), |
---|
64 | #endif |
---|
65 | uint32_t *count |
---|
66 | ) |
---|
67 | { |
---|
68 | Thread_Control *the_thread; |
---|
69 | uint32_t number_broadcasted; |
---|
70 | Thread_Wait_information *waitp; |
---|
71 | |
---|
72 | if ( size > the_message_queue->maximum_message_size ) { |
---|
73 | return CORE_MESSAGE_QUEUE_STATUS_INVALID_SIZE; |
---|
74 | } |
---|
75 | |
---|
76 | /* |
---|
77 | * If there are pending messages, then there can't be threads |
---|
78 | * waiting for us to send them a message. |
---|
79 | * |
---|
80 | * NOTE: This check is critical because threads can block on |
---|
81 | * send and receive and this ensures that we are broadcasting |
---|
82 | * the message to threads waiting to receive -- not to send. |
---|
83 | */ |
---|
84 | |
---|
85 | if ( the_message_queue->number_of_pending_messages != 0 ) { |
---|
86 | *count = 0; |
---|
87 | return CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL; |
---|
88 | } |
---|
89 | |
---|
90 | /* |
---|
91 | * There must be no pending messages if there is a thread waiting to |
---|
92 | * receive a message. |
---|
93 | */ |
---|
94 | number_broadcasted = 0; |
---|
95 | while ((the_thread = |
---|
96 | _Thread_queue_Dequeue(&the_message_queue->Wait_queue))) { |
---|
97 | waitp = &the_thread->Wait; |
---|
98 | number_broadcasted += 1; |
---|
99 | |
---|
100 | _CORE_message_queue_Copy_buffer( |
---|
101 | buffer, |
---|
102 | waitp->return_argument_second.mutable_object, |
---|
103 | size |
---|
104 | ); |
---|
105 | |
---|
106 | *(size_t *) the_thread->Wait.return_argument = size; |
---|
107 | |
---|
108 | #if defined(RTEMS_MULTIPROCESSING) |
---|
109 | if ( !_Objects_Is_local_id( the_thread->Object.id ) ) |
---|
110 | (*api_message_queue_mp_support) ( the_thread, id ); |
---|
111 | #endif |
---|
112 | |
---|
113 | } |
---|
114 | *count = number_broadcasted; |
---|
115 | return CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL; |
---|
116 | } |
---|