1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief RTEMS Message Queue Receive |
---|
5 | * @ingroup ClassicMessageQueue |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2007. |
---|
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.com/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #if HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <rtems/system.h> |
---|
22 | #include <rtems/score/chain.h> |
---|
23 | #include <rtems/score/isr.h> |
---|
24 | #include <rtems/score/coremsgimpl.h> |
---|
25 | #include <rtems/score/object.h> |
---|
26 | #include <rtems/score/states.h> |
---|
27 | #include <rtems/score/thread.h> |
---|
28 | #include <rtems/score/wkspace.h> |
---|
29 | #if defined(RTEMS_MULTIPROCESSING) |
---|
30 | #include <rtems/score/mpci.h> |
---|
31 | #endif |
---|
32 | #include <rtems/rtems/status.h> |
---|
33 | #include <rtems/rtems/attrimpl.h> |
---|
34 | #include <rtems/rtems/messageimpl.h> |
---|
35 | #include <rtems/rtems/optionsimpl.h> |
---|
36 | #include <rtems/rtems/support.h> |
---|
37 | |
---|
38 | rtems_status_code rtems_message_queue_receive( |
---|
39 | rtems_id id, |
---|
40 | void *buffer, |
---|
41 | size_t *size, |
---|
42 | rtems_option option_set, |
---|
43 | rtems_interval timeout |
---|
44 | ) |
---|
45 | { |
---|
46 | register Message_queue_Control *the_message_queue; |
---|
47 | Objects_Locations location; |
---|
48 | bool wait; |
---|
49 | Thread_Control *executing; |
---|
50 | |
---|
51 | if ( !buffer ) |
---|
52 | return RTEMS_INVALID_ADDRESS; |
---|
53 | |
---|
54 | if ( !size ) |
---|
55 | return RTEMS_INVALID_ADDRESS; |
---|
56 | |
---|
57 | the_message_queue = _Message_queue_Get( id, &location ); |
---|
58 | switch ( location ) { |
---|
59 | |
---|
60 | case OBJECTS_LOCAL: |
---|
61 | if ( _Options_Is_no_wait( option_set ) ) |
---|
62 | wait = false; |
---|
63 | else |
---|
64 | wait = true; |
---|
65 | |
---|
66 | executing = _Thread_Executing; |
---|
67 | _CORE_message_queue_Seize( |
---|
68 | &the_message_queue->message_queue, |
---|
69 | executing, |
---|
70 | the_message_queue->Object.id, |
---|
71 | buffer, |
---|
72 | size, |
---|
73 | wait, |
---|
74 | timeout |
---|
75 | ); |
---|
76 | _Objects_Put( &the_message_queue->Object ); |
---|
77 | return _Message_queue_Translate_core_message_queue_return_code( |
---|
78 | executing->Wait.return_code |
---|
79 | ); |
---|
80 | |
---|
81 | #if defined(RTEMS_MULTIPROCESSING) |
---|
82 | case OBJECTS_REMOTE: |
---|
83 | return _Message_queue_MP_Send_request_packet( |
---|
84 | MESSAGE_QUEUE_MP_RECEIVE_REQUEST, |
---|
85 | id, |
---|
86 | buffer, |
---|
87 | size, |
---|
88 | option_set, |
---|
89 | timeout |
---|
90 | ); |
---|
91 | #endif |
---|
92 | |
---|
93 | case OBJECTS_ERROR: |
---|
94 | break; |
---|
95 | } |
---|
96 | |
---|
97 | return RTEMS_INVALID_ID; |
---|
98 | } |
---|