source: rtems/cpukit/score/src/coremsg.c @ aae7f1a1

4.104.115
Last change on this file since aae7f1a1 was aae7f1a1, checked in by Ralf Corsepius <ralf.corsepius@…>, on Dec 22, 2008 at 5:52:32 AM

Eliminate TRUE/FALSE.

  • Property mode set to 100644
File size: 3.7 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  _CORE_message_queue_Set_notify( the_message_queue, NULL, NULL );
66 
67  /*
68   *  Round size up to multiple of a pointer for chain init and
69   *  check for overflow on adding overhead to each message.
70   */
71 
72  allocated_message_size = maximum_message_size;
73  if (allocated_message_size & (sizeof(uint32_t) - 1)) {
74      allocated_message_size += sizeof(uint32_t);
75      allocated_message_size &= ~(sizeof(uint32_t) - 1);
76  }
77   
78  if (allocated_message_size < maximum_message_size)
79    return false;
80
81  /*
82   *  Calculate how much total memory is required for message buffering and
83   *  check for overflow on the multiplication.
84   */
85  message_buffering_required = (size_t) maximum_pending_messages *
86       (allocated_message_size + sizeof(CORE_message_queue_Buffer_control));
87 
88  if (message_buffering_required < allocated_message_size)
89    return false;
90
91  /*
92   *  Attempt to allocate the message memory
93   */
94  the_message_queue->message_buffers = (CORE_message_queue_Buffer *) 
95     _Workspace_Allocate( message_buffering_required );
96 
97  if (the_message_queue->message_buffers == 0)
98    return false;
99 
100  /*
101   *  Initialize the pool of inactive messages, pending messages,
102   *  and set of waiting threads.
103   */
104  _Chain_Initialize (
105    &the_message_queue->Inactive_messages,
106    the_message_queue->message_buffers,
107    (size_t) maximum_pending_messages,
108    allocated_message_size + sizeof( CORE_message_queue_Buffer_control )
109  );
110 
111  _Chain_Initialize_empty( &the_message_queue->Pending_messages );
112 
113  _Thread_queue_Initialize(
114    &the_message_queue->Wait_queue,
115    _CORE_message_queue_Is_priority( the_message_queue_attributes ) ?
116       THREAD_QUEUE_DISCIPLINE_PRIORITY : THREAD_QUEUE_DISCIPLINE_FIFO,
117    STATES_WAITING_FOR_MESSAGE,
118    CORE_MESSAGE_QUEUE_STATUS_TIMEOUT
119  );
120
121  return true;
122}
Note: See TracBrowser for help on using the repository browser.