source: rtems/cpukit/score/src/coremsg.c @ 507d382

4.104.115
Last change on this file since 507d382 was 507d382, checked in by Joel Sherrill <joel.sherrill@…>, on 09/11/09 at 20:00:30

2009-09-11 Joel Sherrill <joel.sherrill@…>

  • score/include/rtems/score/coremsg.h, score/inline/rtems/score/coremsg.inl, score/src/coremsg.c, score/src/coremsginsert.c, score/src/coremsgseize.c, score/src/coremsgsubmit.c, score/src/objectnametoidstring.c: Disable the Core Message Queue features of notification, priority messages, and blocking sends when no API requires them.
  • Property mode set to 100644
File size: 3.8 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
33/*PAGE
34 *
35 *  _CORE_message_queue_Initialize
36 *
37 *  This routine initializes a newly created message queue based on the
38 *  specified data.
39 *
40 *  Input parameters:
41 *    the_message_queue            - the message queue to initialize
42 *    the_class                    - the API specific object class
43 *    the_message_queue_attributes - the message queue's attributes
44 *    maximum_pending_messages     - maximum message and reserved buffer count
45 *    maximum_message_size         - maximum size of each message
46 *
47 *  Output parameters:
48 *    true   - if the message queue is initialized
49 *    false  - if the message queue is NOT initialized
50 */
51
52bool _CORE_message_queue_Initialize(
53  CORE_message_queue_Control    *the_message_queue,
54  CORE_message_queue_Attributes *the_message_queue_attributes,
55  uint32_t                       maximum_pending_messages,
56  size_t                         maximum_message_size
57)
58{
59  size_t message_buffering_required;
60  size_t allocated_message_size;
61
62  the_message_queue->maximum_pending_messages   = maximum_pending_messages;
63  the_message_queue->number_of_pending_messages = 0;
64  the_message_queue->maximum_message_size       = maximum_message_size;
65  #if defined(RTEMS_SCORE_COREMSG_ENABLE_NOTIFICATION)
66    _CORE_message_queue_Set_notify( the_message_queue, NULL, NULL );
67  #endif
68 
69  /*
70   *  Round size up to multiple of a pointer for chain init and
71   *  check for overflow on adding overhead to each message.
72   */
73 
74  allocated_message_size = maximum_message_size;
75  if (allocated_message_size & (sizeof(uint32_t) - 1)) {
76      allocated_message_size += sizeof(uint32_t);
77      allocated_message_size &= ~(sizeof(uint32_t) - 1);
78  }
79   
80  if (allocated_message_size < maximum_message_size)
81    return false;
82
83  /*
84   *  Calculate how much total memory is required for message buffering and
85   *  check for overflow on the multiplication.
86   */
87  message_buffering_required = (size_t) maximum_pending_messages *
88       (allocated_message_size + sizeof(CORE_message_queue_Buffer_control));
89 
90  if (message_buffering_required < allocated_message_size)
91    return false;
92
93  /*
94   *  Attempt to allocate the message memory
95   */
96  the_message_queue->message_buffers = (CORE_message_queue_Buffer *)
97     _Workspace_Allocate( message_buffering_required );
98 
99  if (the_message_queue->message_buffers == 0)
100    return false;
101 
102  /*
103   *  Initialize the pool of inactive messages, pending messages,
104   *  and set of waiting threads.
105   */
106  _Chain_Initialize (
107    &the_message_queue->Inactive_messages,
108    the_message_queue->message_buffers,
109    (size_t) maximum_pending_messages,
110    allocated_message_size + sizeof( CORE_message_queue_Buffer_control )
111  );
112 
113  _Chain_Initialize_empty( &the_message_queue->Pending_messages );
114 
115  _Thread_queue_Initialize(
116    &the_message_queue->Wait_queue,
117    _CORE_message_queue_Is_priority( the_message_queue_attributes ) ?
118       THREAD_QUEUE_DISCIPLINE_PRIORITY : THREAD_QUEUE_DISCIPLINE_FIFO,
119    STATES_WAITING_FOR_MESSAGE,
120    CORE_MESSAGE_QUEUE_STATUS_TIMEOUT
121  );
122
123  return true;
124}
Note: See TracBrowser for help on using the repository browser.