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

4.104.114.84.95
Last change on this file since fa6b0f5 was a8eed23, checked in by Ralf Corsepius <ralf.corsepius@…>, on 01/27/05 at 05:57:05

Include config.h.

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