source: rtems/cpukit/rtems/src/msgqcreate.c @ 484a769

4.104.114.9
Last change on this file since 484a769 was 484a769, checked in by Ralf Corsepius <ralf.corsepius@…>, on Sep 4, 2008 at 5:46:39 PM

Convert to "bool".

  • Property mode set to 100644
File size: 4.2 KB
Line 
1/*
2 *  Message Queue Manager
3 *
4 *
5 *  COPYRIGHT (c) 1989-1999.
6 *  On-Line Applications Research Corporation (OAR).
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *  http://www.rtems.com/license/LICENSE.
11 *
12 *  $Id$
13 */
14
15#if HAVE_CONFIG_H
16#include "config.h"
17#endif
18
19#include <rtems/system.h>
20#include <rtems/score/sysstate.h>
21#include <rtems/score/chain.h>
22#include <rtems/score/isr.h>
23#include <rtems/score/coremsg.h>
24#include <rtems/score/object.h>
25#include <rtems/score/states.h>
26#include <rtems/score/thread.h>
27#include <rtems/score/wkspace.h>
28#if defined(RTEMS_MULTIPROCESSING)
29#include <rtems/score/mpci.h>
30#endif
31#include <rtems/rtems/status.h>
32#include <rtems/rtems/attr.h>
33#include <rtems/rtems/message.h>
34#include <rtems/rtems/options.h>
35#include <rtems/rtems/support.h>
36
37/*PAGE
38 *
39 *  rtems_message_queue_create
40 *
41 *  This directive creates a message queue by allocating and initializing
42 *  a message queue data structure.
43 *
44 *  Input parameters:
45 *    name             - user defined queue name
46 *    count            - maximum message and reserved buffer count
47 *    max_message_size - maximum size of each message
48 *    attribute_set    - process method
49 *    id               - pointer to queue
50 *
51 *  Output parameters:
52 *    id                - queue id
53 *    RTEMS_SUCCESSFUL  - if successful
54 *    error code        - if unsuccessful
55 */
56
57rtems_status_code rtems_message_queue_create(
58  rtems_name          name,
59  uint32_t            count,
60  size_t              max_message_size,
61  rtems_attribute     attribute_set,
62  Objects_Id         *id
63)
64{
65  register Message_queue_Control *the_message_queue;
66  CORE_message_queue_Attributes   the_msgq_attributes;
67#if defined(RTEMS_MULTIPROCESSING)
68  bool                            is_global;
69#endif
70
71  if ( !rtems_is_name_valid( name ) )
72    return RTEMS_INVALID_NAME;
73
74  if ( !id )
75    return RTEMS_INVALID_ADDRESS;
76
77#if defined(RTEMS_MULTIPROCESSING)
78  if ( (is_global = _Attributes_Is_global( attribute_set ) ) &&
79       !_System_state_Is_multiprocessing )
80    return RTEMS_MP_NOT_CONFIGURED;
81#endif
82
83  if ( count == 0 )
84      return RTEMS_INVALID_NUMBER;
85
86  if ( max_message_size == 0 )
87      return RTEMS_INVALID_SIZE;
88
89#if defined(RTEMS_MULTIPROCESSING)
90#if 1
91  /*
92   * I am not 100% sure this should be an error.
93   * It seems reasonable to create a que with a large max size,
94   * and then just send smaller msgs from remote (or all) nodes.
95   */
96
97  if ( is_global && (_MPCI_table->maximum_packet_size < max_message_size) )
98    return RTEMS_INVALID_SIZE;
99#endif
100#endif
101
102  _Thread_Disable_dispatch();              /* protects object pointer */
103
104  the_message_queue = _Message_queue_Allocate();
105
106  if ( !the_message_queue ) {
107    _Thread_Enable_dispatch();
108    return RTEMS_TOO_MANY;
109  }
110
111#if defined(RTEMS_MULTIPROCESSING)
112  if ( is_global &&
113    !( _Objects_MP_Allocate_and_open( &_Message_queue_Information,
114                              name, the_message_queue->Object.id, FALSE ) ) ) {
115    _Message_queue_Free( the_message_queue );
116    _Thread_Enable_dispatch();
117    return RTEMS_TOO_MANY;
118  }
119#endif
120
121  the_message_queue->attribute_set = attribute_set;
122
123  if (_Attributes_Is_priority( attribute_set ) )
124    the_msgq_attributes.discipline = CORE_MESSAGE_QUEUE_DISCIPLINES_PRIORITY;
125  else
126    the_msgq_attributes.discipline = CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO;
127
128  if ( ! _CORE_message_queue_Initialize(
129           &the_message_queue->message_queue,
130           &the_msgq_attributes,
131           count,
132           max_message_size
133         ) ) {
134#if defined(RTEMS_MULTIPROCESSING)
135    if ( is_global )
136        _Objects_MP_Close(
137          &_Message_queue_Information, the_message_queue->Object.id);
138#endif
139
140    _Message_queue_Free( the_message_queue );
141    _Thread_Enable_dispatch();
142    return RTEMS_UNSATISFIED;
143  }
144
145  _Objects_Open(
146    &_Message_queue_Information,
147    &the_message_queue->Object,
148    (Objects_Name) name
149  );
150
151  *id = the_message_queue->Object.id;
152
153#if defined(RTEMS_MULTIPROCESSING)
154  if ( is_global )
155    _Message_queue_MP_Send_process_packet(
156      MESSAGE_QUEUE_MP_ANNOUNCE_CREATE,
157      the_message_queue->Object.id,
158      name,
159      0
160    );
161#endif
162
163  _Thread_Enable_dispatch();
164  return RTEMS_SUCCESSFUL;
165}
Note: See TracBrowser for help on using the repository browser.