1 | /* |
---|
2 | * Message Queue Manager |
---|
3 | * |
---|
4 | * |
---|
5 | * COPYRIGHT (c) 1989-2007. |
---|
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_receive |
---|
40 | * |
---|
41 | * This directive dequeues a message from the designated message queue |
---|
42 | * and copies it into the requesting thread's buffer. |
---|
43 | * |
---|
44 | * Input parameters: |
---|
45 | * id - queue id |
---|
46 | * buffer - pointer to message buffer |
---|
47 | * size - size of message receive |
---|
48 | * option_set - options on receive |
---|
49 | * timeout - number of ticks to wait |
---|
50 | * |
---|
51 | * Output parameters: |
---|
52 | * RTEMS_SUCCESSFUL - if successful |
---|
53 | * error code - if unsuccessful |
---|
54 | */ |
---|
55 | |
---|
56 | rtems_status_code rtems_message_queue_receive( |
---|
57 | Objects_Id id, |
---|
58 | void *buffer, |
---|
59 | size_t *size, |
---|
60 | rtems_option option_set, |
---|
61 | rtems_interval timeout |
---|
62 | ) |
---|
63 | { |
---|
64 | register Message_queue_Control *the_message_queue; |
---|
65 | Objects_Locations location; |
---|
66 | bool wait; |
---|
67 | |
---|
68 | if ( !buffer ) |
---|
69 | return RTEMS_INVALID_ADDRESS; |
---|
70 | |
---|
71 | if ( !size ) |
---|
72 | return RTEMS_INVALID_ADDRESS; |
---|
73 | |
---|
74 | the_message_queue = _Message_queue_Get( id, &location ); |
---|
75 | switch ( location ) { |
---|
76 | |
---|
77 | case OBJECTS_LOCAL: |
---|
78 | if ( _Options_Is_no_wait( option_set ) ) |
---|
79 | wait = false; |
---|
80 | else |
---|
81 | wait = true; |
---|
82 | |
---|
83 | _CORE_message_queue_Seize( |
---|
84 | &the_message_queue->message_queue, |
---|
85 | the_message_queue->Object.id, |
---|
86 | buffer, |
---|
87 | size, |
---|
88 | wait, |
---|
89 | timeout |
---|
90 | ); |
---|
91 | _Thread_Enable_dispatch(); |
---|
92 | return _Message_queue_Translate_core_message_queue_return_code( |
---|
93 | _Thread_Executing->Wait.return_code |
---|
94 | ); |
---|
95 | |
---|
96 | #if defined(RTEMS_MULTIPROCESSING) |
---|
97 | case OBJECTS_REMOTE: |
---|
98 | return _Message_queue_MP_Send_request_packet( |
---|
99 | MESSAGE_QUEUE_MP_RECEIVE_REQUEST, |
---|
100 | id, |
---|
101 | buffer, |
---|
102 | size, |
---|
103 | option_set, |
---|
104 | timeout |
---|
105 | ); |
---|
106 | #endif |
---|
107 | |
---|
108 | case OBJECTS_ERROR: |
---|
109 | break; |
---|
110 | } |
---|
111 | |
---|
112 | return RTEMS_INVALID_ID; |
---|
113 | } |
---|