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