OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [cpukit/] [rtems/] [src/] [msgqcreate.c] - Blame information for rev 1780

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1026 ivang
/*
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.OARcorp.com/rtems/license.html.
11
 *
12
 *  msgqcreate.c,v 1.4 2002/07/01 22:32:31 joel Exp
13
 */
14
 
15
#include <rtems/system.h>
16
#include <rtems/score/sysstate.h>
17
#include <rtems/score/chain.h>
18
#include <rtems/score/isr.h>
19
#include <rtems/score/coremsg.h>
20
#include <rtems/score/object.h>
21
#include <rtems/score/states.h>
22
#include <rtems/score/thread.h>
23
#include <rtems/score/wkspace.h>
24
#if defined(RTEMS_MULTIPROCESSING)
25
#include <rtems/score/mpci.h>
26
#endif
27
#include <rtems/rtems/status.h>
28
#include <rtems/rtems/attr.h>
29
#include <rtems/rtems/message.h>
30
#include <rtems/rtems/options.h>
31
#include <rtems/rtems/support.h>
32
 
33
/*PAGE
34
 *
35
 *  rtems_message_queue_create
36
 *
37
 *  This directive creates a message queue by allocating and initializing
38
 *  a message queue data structure.
39
 *
40
 *  Input parameters:
41
 *    name             - user defined queue name
42
 *    count            - maximum message and reserved buffer count
43
 *    max_message_size - maximum size of each message
44
 *    attribute_set    - process method
45
 *    id               - pointer to queue
46
 *
47
 *  Output parameters:
48
 *    id                - queue id
49
 *    RTEMS_SUCCESSFUL  - if successful
50
 *    error code        - if unsuccessful
51
 */
52
 
53
rtems_status_code rtems_message_queue_create(
54
  rtems_name          name,
55
  unsigned32          count,
56
  unsigned32          max_message_size,
57
  rtems_attribute     attribute_set,
58
  Objects_Id         *id
59
)
60
{
61
  register Message_queue_Control *the_message_queue;
62
  CORE_message_queue_Attributes   the_msgq_attributes;
63
#if defined(RTEMS_MULTIPROCESSING)
64
  boolean                         is_global;
65
#endif
66
 
67
  if ( !rtems_is_name_valid( name ) )
68
    return RTEMS_INVALID_NAME;
69
 
70
#if defined(RTEMS_MULTIPROCESSING)
71
  if ( (is_global = _Attributes_Is_global( attribute_set ) ) &&
72
       !_System_state_Is_multiprocessing )
73
    return RTEMS_MP_NOT_CONFIGURED;
74
#endif
75
 
76
  if ( count == 0 )
77
      return RTEMS_INVALID_NUMBER;
78
 
79
  if ( max_message_size == 0 )
80
      return RTEMS_INVALID_SIZE;
81
 
82
#if defined(RTEMS_MULTIPROCESSING)
83
#if 1
84
  /*
85
   * I am not 100% sure this should be an error.
86
   * It seems reasonable to create a que with a large max size,
87
   * and then just send smaller msgs from remote (or all) nodes.
88
   */
89
 
90
  if ( is_global && (_MPCI_table->maximum_packet_size < max_message_size) )
91
    return RTEMS_INVALID_SIZE;
92
#endif
93
#endif
94
 
95
  _Thread_Disable_dispatch();              /* protects object pointer */
96
 
97
  the_message_queue = _Message_queue_Allocate( count, max_message_size );
98
 
99
  if ( !the_message_queue ) {
100
    _Thread_Enable_dispatch();
101
    return RTEMS_TOO_MANY;
102
  }
103
 
104
#if defined(RTEMS_MULTIPROCESSING)
105
  if ( is_global &&
106
    !( _Objects_MP_Allocate_and_open( &_Message_queue_Information,
107
                              name, the_message_queue->Object.id, FALSE ) ) ) {
108
    _Message_queue_Free( the_message_queue );
109
    _Thread_Enable_dispatch();
110
    return RTEMS_TOO_MANY;
111
  }
112
#endif
113
 
114
  the_message_queue->attribute_set = attribute_set;
115
 
116
  if (_Attributes_Is_priority( attribute_set ) )
117
    the_msgq_attributes.discipline = CORE_MESSAGE_QUEUE_DISCIPLINES_PRIORITY;
118
  else
119
    the_msgq_attributes.discipline = CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO;
120
 
121
  if ( ! _CORE_message_queue_Initialize(
122
           &the_message_queue->message_queue,
123
           &the_msgq_attributes,
124
           count,
125
           max_message_size
126
         ) ) {
127
#if defined(RTEMS_MULTIPROCESSING)
128
    if ( is_global )
129
        _Objects_MP_Close(
130
          &_Message_queue_Information, the_message_queue->Object.id);
131
#endif
132
 
133
    _Message_queue_Free( the_message_queue );
134
    _Thread_Enable_dispatch();
135
    return RTEMS_TOO_MANY;
136
  }
137
 
138
  _Objects_Open(
139
    &_Message_queue_Information,
140
    &the_message_queue->Object,
141
    name
142
  );
143
 
144
  *id = the_message_queue->Object.id;
145
 
146
#if defined(RTEMS_MULTIPROCESSING)
147
  if ( is_global )
148
    _Message_queue_MP_Send_process_packet(
149
      MESSAGE_QUEUE_MP_ANNOUNCE_CREATE,
150
      the_message_queue->Object.id,
151
      name,
152
 
153
    );
154
#endif
155
 
156
  _Thread_Enable_dispatch();
157
  return RTEMS_SUCCESSFUL;
158
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.