source: rtems/cpukit/score/src/coremsgbroadcast.c @ 25f5730f

4.11
Last change on this file since 25f5730f was c499856, checked in by Chris Johns <chrisj@…>, on Mar 20, 2014 at 9:10:47 PM

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 2.5 KB
Line 
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.org/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <rtems/score/coremsgimpl.h>
22#include <rtems/score/objectimpl.h>
23#include <rtems/score/thread.h>
24
25CORE_message_queue_Status _CORE_message_queue_Broadcast(
26  CORE_message_queue_Control                *the_message_queue,
27  const void                                *buffer,
28  size_t                                     size,
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
36  uint32_t                                  *count
37)
38{
39  Thread_Control          *the_thread;
40  uint32_t                 number_broadcasted;
41  Thread_Wait_information *waitp;
42
43  if ( size > the_message_queue->maximum_message_size ) {
44    return CORE_MESSAGE_QUEUE_STATUS_INVALID_SIZE;
45  }
46
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   */
65  number_broadcasted = 0;
66  while ((the_thread =
67          _Thread_queue_Dequeue(&the_message_queue->Wait_queue))) {
68    waitp = &the_thread->Wait;
69    number_broadcasted += 1;
70
71    _CORE_message_queue_Copy_buffer(
72      buffer,
73      waitp->return_argument_second.mutable_object,
74      size
75    );
76
77    *(size_t *) the_thread->Wait.return_argument = size;
78
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
83
84  }
85  *count = number_broadcasted;
86  return CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL;
87}
Note: See TracBrowser for help on using the repository browser.