source: rtems/cpukit/score/src/coremsgbroadcast.c @ 22ce0881

4.104.114.95
Last change on this file since 22ce0881 was f773c012, checked in by Joel Sherrill <joel.sherrill@…>, on 08/05/08 at 13:32:39

2008-08-04 Sebastian Huber <sebastian.huber@…>

  • rtems/include/rtems/rtems/sem.h, rtems/src/semobtain.c: Changed option set type to rtems_option.
  • score/src/objectgetinfo.c: Check return value of _Objects_API_maximum_class().
  • libmisc/monitor/mon-mpci.c, libmisc/monitor/monitor.h, rtems/include/rtems/rtems/message.h, rtems/src/msgmp.c, rtems/src/msgqallocate.c, rtems/src/msgqbroadcast.c, rtems/src/msgqcreate.c, rtems/src/msgqreceive.c, rtems/src/msgqsend.c, rtems/src/msgqurgent.c, score/include/rtems/score/coremsg.h, score/include/rtems/score/mpci.h, score/include/rtems/score/thread.h, score/inline/rtems/score/coremsg.inl, score/src/coremsg.c, score/src/coremsgbroadcast.c, score/src/coremsgseize.c, score/src/coremsgsubmit.c: Removed parameters of _Message_queue_Allocate(). Changed option set type to rtems_option. Changed type of maximum message and packet size to size_t. Changed the input buffer type for message send functions to "const void *". Changed the pointer to the second return argument in the thread wait information to a union. This union can contain a pointer to an immutable or a mutable object. This is somewhat fragile. An alternative would be to add a third pointer for immutable objects, but this would increase the structure size.
  • Property mode set to 100644
File size: 3.5 KB
Line 
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-1999.
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#if defined(RTEMS_MULTIPROCESSING)
33#include <rtems/score/mpci.h>
34#endif
35
36/*PAGE
37 *
38 *  _CORE_message_queue_Broadcast
39 *
40 *  This function sends a message for every thread waiting on the queue and
41 *  returns the number of threads made ready by the message.
42 *
43 *  Input parameters:
44 *    the_message_queue            - message is submitted to this message queue
45 *    buffer                       - pointer to message buffer
46 *    size                         - size in bytes of message to send
47 *    id                           - id of message queue
48 *    api_message_queue_mp_support - api specific mp support callout
49 *    count                        - area to store number of threads made ready
50 *
51 *  Output parameters:
52 *    count                         - number of threads made ready
53 *    CORE_MESSAGE_QUEUE_SUCCESSFUL - if successful
54 *    error code                    - if unsuccessful
55 */
56
57CORE_message_queue_Status _CORE_message_queue_Broadcast(
58  CORE_message_queue_Control                *the_message_queue,
59  const void                                *buffer,
60  size_t                                     size,
61  Objects_Id                                 id,
62  CORE_message_queue_API_mp_support_callout  api_message_queue_mp_support,
63  uint32_t                                  *count
64)
65{
66  Thread_Control          *the_thread;
67  uint32_t                 number_broadcasted;
68  Thread_Wait_information *waitp;
69  size_t                   constrained_size;
70
71  /*
72   *  If there are pending messages, then there can't be threads
73   *  waiting for us to send them a message.
74   *
75   *  NOTE: This check is critical because threads can block on
76   *        send and receive and this ensures that we are broadcasting
77   *        the message to threads waiting to receive -- not to send.
78   */
79
80  if ( the_message_queue->number_of_pending_messages != 0 ) {
81    *count = 0;
82    return CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL;
83  }
84
85  /*
86   *  There must be no pending messages if there is a thread waiting to
87   *  receive a message.
88   */
89
90  number_broadcasted = 0;
91  while ((the_thread = _Thread_queue_Dequeue(&the_message_queue->Wait_queue))) {
92    waitp = &the_thread->Wait;
93    number_broadcasted += 1;
94
95    constrained_size = size;
96    if ( size > the_message_queue->maximum_message_size )
97        constrained_size = the_message_queue->maximum_message_size;
98
99    _CORE_message_queue_Copy_buffer(
100      buffer,
101      waitp->return_argument_second.mutable_object,
102      constrained_size
103    );
104
105    *(size_t *) the_thread->Wait.return_argument = size;
106
107#if defined(RTEMS_MULTIPROCESSING)
108    if ( !_Objects_Is_local_id( the_thread->Object.id ) )
109      (*api_message_queue_mp_support) ( the_thread, id );
110#endif
111
112  }
113  *count = number_broadcasted;
114  return CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL;
115}
Note: See TracBrowser for help on using the repository browser.