source: rtems/cpukit/rtems/src/msgmp.c @ 081d03d

5
Last change on this file since 081d03d was 081d03d, checked in by Sebastian Huber <sebastian.huber@…>, on 03/30/16 at 06:08:44

score: Fix set but not used warning

No need to add an assert due to the fatal error parameter passed to
_Objects_MP_Allocate_and_open().

  • Property mode set to 100644
File size: 13.3 KB
Line 
1/**
2 * @file
3 *
4 * @brief Multiprocessing Support for the Message Queue Manager
5 * @ingroup ClassicMsgMP Message Queue MP Support
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2008.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.org/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <rtems/rtems/messageimpl.h>
22#include <rtems/rtems/optionsimpl.h>
23#include <rtems/score/coremsgimpl.h>
24#include <rtems/score/statesimpl.h>
25#include <rtems/score/threadimpl.h>
26
27RTEMS_STATIC_ASSERT(
28  MESSAGE_QUEUE_MP_PACKET_SIZE <= MP_PACKET_MINIMUM_PACKET_SIZE,
29  Message_queue_MP_Packet
30);
31
32/*
33 *  _Message_queue_MP_Send_process_packet
34 *
35 */
36
37void _Message_queue_MP_Send_process_packet (
38  Message_queue_MP_Remote_operations  operation,
39  Objects_Id                          message_queue_id,
40  rtems_name                          name,
41  Objects_Id                          proxy_id
42)
43{
44  Message_queue_MP_Packet *the_packet;
45  uint32_t                 node;
46
47  switch ( operation ) {
48
49    case MESSAGE_QUEUE_MP_ANNOUNCE_CREATE:
50    case MESSAGE_QUEUE_MP_ANNOUNCE_DELETE:
51    case MESSAGE_QUEUE_MP_EXTRACT_PROXY:
52
53      the_packet                    = _Message_queue_MP_Get_packet();
54      the_packet->Prefix.the_class  = MP_PACKET_MESSAGE_QUEUE;
55      the_packet->Prefix.length     = MESSAGE_QUEUE_MP_PACKET_SIZE;
56      the_packet->Prefix.to_convert = MESSAGE_QUEUE_MP_PACKET_SIZE;
57      the_packet->operation         = operation;
58      the_packet->Prefix.id         = message_queue_id;
59      the_packet->name              = name;
60      the_packet->proxy_id          = proxy_id;
61
62      if ( operation == MESSAGE_QUEUE_MP_EXTRACT_PROXY )
63         node = _Objects_Get_node( message_queue_id );
64      else
65         node = MPCI_ALL_NODES;
66
67      _MPCI_Send_process_packet( node, &the_packet->Prefix );
68      break;
69
70    case MESSAGE_QUEUE_MP_RECEIVE_REQUEST:
71    case MESSAGE_QUEUE_MP_RECEIVE_RESPONSE:
72    case MESSAGE_QUEUE_MP_SEND_REQUEST:
73    case MESSAGE_QUEUE_MP_SEND_RESPONSE:
74    case MESSAGE_QUEUE_MP_URGENT_REQUEST:
75    case MESSAGE_QUEUE_MP_URGENT_RESPONSE:
76    case MESSAGE_QUEUE_MP_BROADCAST_REQUEST:
77    case MESSAGE_QUEUE_MP_BROADCAST_RESPONSE:
78    case MESSAGE_QUEUE_MP_FLUSH_REQUEST:
79    case MESSAGE_QUEUE_MP_FLUSH_RESPONSE:
80    case MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_REQUEST:
81    case MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_RESPONSE:
82      break;
83
84  }
85}
86
87/*
88 *  _Message_queue_MP_Send_request_packet
89 *
90 */
91
92rtems_status_code _Message_queue_MP_Send_request_packet (
93  Message_queue_MP_Remote_operations  operation,
94  Objects_Id                          message_queue_id,
95  const void                         *buffer,
96  size_t                             *size_p,
97  rtems_option                        option_set,
98  rtems_interval                      timeout
99)
100{
101  Message_queue_MP_Packet *the_packet;
102
103  switch ( operation ) {
104
105    case MESSAGE_QUEUE_MP_SEND_REQUEST:
106    case MESSAGE_QUEUE_MP_URGENT_REQUEST:
107    case MESSAGE_QUEUE_MP_BROADCAST_REQUEST:
108    case MESSAGE_QUEUE_MP_FLUSH_REQUEST:
109    case MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_REQUEST:
110
111      the_packet                    = _Message_queue_MP_Get_packet();
112      the_packet->Prefix.the_class  = MP_PACKET_MESSAGE_QUEUE;
113      the_packet->Prefix.length     = MESSAGE_QUEUE_MP_PACKET_SIZE;
114      if ( size_p )
115        the_packet->Prefix.length     += *size_p;
116      the_packet->Prefix.to_convert = MESSAGE_QUEUE_MP_PACKET_SIZE;
117
118      /*
119       * make sure message is not too big for our MPCI driver
120       * We have to check it here instead of waiting for MPCI because
121       * we are about to slam in the payload
122       */
123
124      if (the_packet->Prefix.length > _MPCI_table->maximum_packet_size) {
125          return RTEMS_INVALID_SIZE;
126      }
127
128      if (! _Options_Is_no_wait(option_set))
129          the_packet->Prefix.timeout = timeout;
130
131      the_packet->operation  = operation;
132      the_packet->Prefix.id  = message_queue_id;
133      the_packet->option_set = option_set;
134
135      /*
136       * Copy the data into place if needed
137       */
138
139      if (buffer) {
140          the_packet->Buffer.size = *size_p;
141          _CORE_message_queue_Copy_buffer(
142            buffer,
143            the_packet->Buffer.buffer,
144            *size_p
145          );
146      }
147
148      return (rtems_status_code) _MPCI_Send_request_packet(
149        _Objects_Get_node(message_queue_id),
150        &the_packet->Prefix,
151        STATES_WAITING_FOR_MESSAGE,
152        RTEMS_TIMEOUT
153      );
154      break;
155
156    case MESSAGE_QUEUE_MP_RECEIVE_REQUEST:
157
158      the_packet                    = _Message_queue_MP_Get_packet();
159      the_packet->Prefix.the_class  = MP_PACKET_MESSAGE_QUEUE;
160      the_packet->Prefix.length     = MESSAGE_QUEUE_MP_PACKET_SIZE;
161      the_packet->Prefix.to_convert = MESSAGE_QUEUE_MP_PACKET_SIZE;
162
163      if (! _Options_Is_no_wait(option_set))
164          the_packet->Prefix.timeout = timeout;
165
166      the_packet->operation  = MESSAGE_QUEUE_MP_RECEIVE_REQUEST;
167      the_packet->Prefix.id  = message_queue_id;
168      the_packet->option_set = option_set;
169      the_packet->size       = 0;        /* just in case of an error */
170
171      _Thread_Executing->Wait.return_argument_second.immutable_object = buffer;
172      _Thread_Executing->Wait.return_argument = size_p;
173
174      return (rtems_status_code) _MPCI_Send_request_packet(
175        _Objects_Get_node(message_queue_id),
176        &the_packet->Prefix,
177        STATES_WAITING_FOR_MESSAGE,
178        RTEMS_TIMEOUT
179      );
180      break;
181
182    case MESSAGE_QUEUE_MP_ANNOUNCE_CREATE:
183    case MESSAGE_QUEUE_MP_ANNOUNCE_DELETE:
184    case MESSAGE_QUEUE_MP_EXTRACT_PROXY:
185    case MESSAGE_QUEUE_MP_RECEIVE_RESPONSE:
186    case MESSAGE_QUEUE_MP_SEND_RESPONSE:
187    case MESSAGE_QUEUE_MP_URGENT_RESPONSE:
188    case MESSAGE_QUEUE_MP_BROADCAST_RESPONSE:
189    case MESSAGE_QUEUE_MP_FLUSH_RESPONSE:
190    case MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_RESPONSE:
191      break;
192  }
193
194  return RTEMS_SUCCESSFUL;
195}
196
197/*
198 *  _Message_queue_MP_Send_response_packet
199 *
200 */
201
202void _Message_queue_MP_Send_response_packet (
203  Message_queue_MP_Remote_operations  operation,
204  Objects_Id                          message_queue_id,
205  Thread_Control                     *the_thread
206)
207{
208  Message_queue_MP_Packet *the_packet;
209
210  switch ( operation ) {
211
212    case MESSAGE_QUEUE_MP_RECEIVE_RESPONSE:
213    case MESSAGE_QUEUE_MP_SEND_RESPONSE:
214    case MESSAGE_QUEUE_MP_URGENT_RESPONSE:
215    case MESSAGE_QUEUE_MP_BROADCAST_RESPONSE:
216    case MESSAGE_QUEUE_MP_FLUSH_RESPONSE:
217    case MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_RESPONSE:
218
219      the_packet = ( Message_queue_MP_Packet *) the_thread->receive_packet;
220
221/*
222 *  The packet being returned already contains the class, length, and
223 *  to_convert fields, therefore they are not set in this routine.
224 *
225 *  Exception: MESSAGE_QUEUE_MP_RECEIVE_RESPONSE needs payload length
226 *             added to 'length'
227 */
228      the_packet->operation = operation;
229      the_packet->Prefix.id = the_packet->Prefix.source_tid;
230
231      if (operation == MESSAGE_QUEUE_MP_RECEIVE_RESPONSE)
232          the_packet->Prefix.length += the_packet->size;
233
234      _MPCI_Send_response_packet(
235        _Objects_Get_node( the_packet->Prefix.source_tid ),
236        &the_packet->Prefix
237      );
238      break;
239
240    case MESSAGE_QUEUE_MP_ANNOUNCE_CREATE:
241    case MESSAGE_QUEUE_MP_ANNOUNCE_DELETE:
242    case MESSAGE_QUEUE_MP_EXTRACT_PROXY:
243    case MESSAGE_QUEUE_MP_RECEIVE_REQUEST:
244    case MESSAGE_QUEUE_MP_SEND_REQUEST:
245    case MESSAGE_QUEUE_MP_URGENT_REQUEST:
246    case MESSAGE_QUEUE_MP_BROADCAST_REQUEST:
247    case MESSAGE_QUEUE_MP_FLUSH_REQUEST:
248    case MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_REQUEST:
249      break;
250
251  }
252}
253
254/*
255 *
256 *  _Message_queue_MP_Process_packet
257 *
258 */
259
260void _Message_queue_MP_Process_packet (
261  rtems_packet_prefix   *the_packet_prefix
262)
263{
264  Message_queue_MP_Packet *the_packet;
265  Thread_Control          *the_thread;
266
267  the_packet = (Message_queue_MP_Packet *) the_packet_prefix;
268
269  switch ( the_packet->operation ) {
270
271    case MESSAGE_QUEUE_MP_ANNOUNCE_CREATE:
272
273      _Objects_MP_Allocate_and_open(
274        &_Message_queue_Information,
275        the_packet->name,
276        the_packet->Prefix.id,
277        true
278      );
279
280      _MPCI_Return_packet( the_packet_prefix );
281      break;
282
283    case MESSAGE_QUEUE_MP_ANNOUNCE_DELETE:
284
285      _Objects_MP_Close( &_Message_queue_Information, the_packet->Prefix.id );
286
287      _MPCI_Return_packet( the_packet_prefix );
288      break;
289
290    case MESSAGE_QUEUE_MP_EXTRACT_PROXY:
291
292      the_thread = _Thread_MP_Find_proxy( the_packet->proxy_id );
293
294      if (! _Thread_Is_null( the_thread ) )
295         _Thread_queue_Extract( the_thread );
296
297      _MPCI_Return_packet( the_packet_prefix );
298      break;
299
300    case MESSAGE_QUEUE_MP_RECEIVE_REQUEST:
301
302      the_packet->Prefix.return_code = rtems_message_queue_receive(
303        the_packet->Prefix.id,
304        the_packet->Buffer.buffer,
305        &the_packet->size,
306        the_packet->option_set,
307        the_packet->Prefix.timeout
308      );
309
310      if ( the_packet->Prefix.return_code != RTEMS_PROXY_BLOCKING )
311        _Message_queue_MP_Send_response_packet(
312          MESSAGE_QUEUE_MP_RECEIVE_RESPONSE,
313          the_packet->Prefix.id,
314          _Thread_Executing
315        );
316      break;
317
318    case MESSAGE_QUEUE_MP_RECEIVE_RESPONSE:
319
320      the_thread = _MPCI_Process_response( the_packet_prefix );
321
322      if (the_packet->Prefix.return_code == RTEMS_SUCCESSFUL) {
323        *(size_t *) the_thread->Wait.return_argument =
324           the_packet->size;
325
326        _CORE_message_queue_Copy_buffer(
327          the_packet->Buffer.buffer,
328          the_thread->Wait.return_argument_second.mutable_object,
329          the_packet->size
330        );
331      }
332
333      _MPCI_Return_packet( the_packet_prefix );
334      break;
335
336    case MESSAGE_QUEUE_MP_SEND_REQUEST:
337
338      the_packet->Prefix.return_code = rtems_message_queue_send(
339        the_packet->Prefix.id,
340        the_packet->Buffer.buffer,
341        the_packet->Buffer.size
342      );
343
344      _Message_queue_MP_Send_response_packet(
345        MESSAGE_QUEUE_MP_SEND_RESPONSE,
346        the_packet->Prefix.id,
347        _Thread_Executing
348      );
349      break;
350
351    case MESSAGE_QUEUE_MP_SEND_RESPONSE:
352    case MESSAGE_QUEUE_MP_URGENT_RESPONSE:
353
354      the_thread = _MPCI_Process_response( the_packet_prefix );
355
356      _MPCI_Return_packet( the_packet_prefix );
357      break;
358
359    case MESSAGE_QUEUE_MP_URGENT_REQUEST:
360
361      the_packet->Prefix.return_code = rtems_message_queue_urgent(
362        the_packet->Prefix.id,
363        the_packet->Buffer.buffer,
364        the_packet->Buffer.size
365      );
366
367      _Message_queue_MP_Send_response_packet(
368        MESSAGE_QUEUE_MP_URGENT_RESPONSE,
369        the_packet->Prefix.id,
370        _Thread_Executing
371      );
372      break;
373
374    case MESSAGE_QUEUE_MP_BROADCAST_REQUEST:
375
376      the_packet->Prefix.return_code = rtems_message_queue_broadcast(
377        the_packet->Prefix.id,
378        the_packet->Buffer.buffer,
379        the_packet->Buffer.size,
380        &the_packet->count
381      );
382
383      _Message_queue_MP_Send_response_packet(
384        MESSAGE_QUEUE_MP_BROADCAST_RESPONSE,
385        the_packet->Prefix.id,
386        _Thread_Executing
387      );
388      break;
389
390    case MESSAGE_QUEUE_MP_BROADCAST_RESPONSE:
391    case MESSAGE_QUEUE_MP_FLUSH_RESPONSE:
392    case MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_RESPONSE:
393
394      the_thread = _MPCI_Process_response( the_packet_prefix );
395
396      *(uint32_t *) the_thread->Wait.return_argument = the_packet->count;
397
398      _MPCI_Return_packet( the_packet_prefix );
399      break;
400
401    case MESSAGE_QUEUE_MP_FLUSH_REQUEST:
402
403      the_packet->Prefix.return_code = rtems_message_queue_flush(
404        the_packet->Prefix.id,
405        &the_packet->count
406      );
407
408      _Message_queue_MP_Send_response_packet(
409        MESSAGE_QUEUE_MP_FLUSH_RESPONSE,
410        the_packet->Prefix.id,
411        _Thread_Executing
412      );
413      break;
414
415    case MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_REQUEST:
416
417      the_packet->Prefix.return_code = rtems_message_queue_get_number_pending(
418        the_packet->Prefix.id,
419        &the_packet->count
420      );
421
422      _Message_queue_MP_Send_response_packet(
423        MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_RESPONSE,
424        the_packet->Prefix.id,
425        _Thread_Executing
426      );
427      break;
428
429  }
430}
431
432/*
433 *  _Message_queue_MP_Send_object_was_deleted
434 *
435 */
436
437void _Message_queue_MP_Send_object_was_deleted (
438  Thread_Control  *the_proxy
439)
440{
441  the_proxy->receive_packet->return_code = RTEMS_OBJECT_WAS_DELETED;
442
443  _Message_queue_MP_Send_response_packet(
444    MESSAGE_QUEUE_MP_RECEIVE_RESPONSE,
445    the_proxy->Wait.id,
446    the_proxy
447  );
448}
449
450/*
451 *  _Message_queue_MP_Send_extract_proxy
452 *
453 */
454
455void _Message_queue_MP_Send_extract_proxy (
456  void           *argument
457)
458{
459  Thread_Control *the_thread = (Thread_Control *)argument;
460
461  _Message_queue_MP_Send_process_packet(
462    MESSAGE_QUEUE_MP_EXTRACT_PROXY,
463    the_thread->Wait.id,
464    (rtems_name) 0,
465    the_thread->Object.id
466  );
467}
468
469/*
470 *  _Message_queue_MP_Get_packet
471 *
472 */
473
474Message_queue_MP_Packet *_Message_queue_MP_Get_packet ( void )
475{
476  return ( (Message_queue_MP_Packet *) _MPCI_Get_packet() );
477}
478
479
480/*
481 *  _Message_queue_Core_message_queue_mp_support
482 *
483 *  Input parameters:
484 *    the_thread - the remote thread the message was submitted to
485 *    id         - id of the message queue
486 *
487 *  Output parameters: NONE
488 */
489
490void  _Message_queue_Core_message_queue_mp_support (
491  Thread_Control *the_thread,
492  Objects_Id      id
493)
494{
495  the_thread->receive_packet->return_code = RTEMS_SUCCESSFUL;
496
497  _Message_queue_MP_Send_response_packet(
498    MESSAGE_QUEUE_MP_RECEIVE_RESPONSE,
499    id,
500    the_thread
501  );
502}
503
504/* end of file */
Note: See TracBrowser for help on using the repository browser.