1 | /* |
---|
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 | * $Id$ |
---|
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_receive |
---|
36 | * |
---|
37 | * This directive dequeues a message from the designated message queue |
---|
38 | * and copies it into the requesting thread's buffer. |
---|
39 | * |
---|
40 | * Input parameters: |
---|
41 | * id - queue id |
---|
42 | * buffer - pointer to message buffer |
---|
43 | * size - size of message receive |
---|
44 | * option_set - options on receive |
---|
45 | * timeout - number of ticks to wait |
---|
46 | * |
---|
47 | * Output parameters: |
---|
48 | * RTEMS_SUCCESSFUL - if successful |
---|
49 | * error code - if unsuccessful |
---|
50 | */ |
---|
51 | |
---|
52 | rtems_status_code rtems_message_queue_receive( |
---|
53 | Objects_Id id, |
---|
54 | void *buffer, |
---|
55 | unsigned32 *size, |
---|
56 | unsigned32 option_set, |
---|
57 | rtems_interval timeout |
---|
58 | ) |
---|
59 | { |
---|
60 | register Message_queue_Control *the_message_queue; |
---|
61 | Objects_Locations location; |
---|
62 | boolean wait; |
---|
63 | |
---|
64 | the_message_queue = _Message_queue_Get( id, &location ); |
---|
65 | switch ( location ) { |
---|
66 | |
---|
67 | case OBJECTS_REMOTE: |
---|
68 | #if defined(RTEMS_MULTIPROCESSING) |
---|
69 | return _Message_queue_MP_Send_request_packet( |
---|
70 | MESSAGE_QUEUE_MP_RECEIVE_REQUEST, |
---|
71 | id, |
---|
72 | buffer, |
---|
73 | size, |
---|
74 | option_set, |
---|
75 | timeout |
---|
76 | ); |
---|
77 | #endif |
---|
78 | |
---|
79 | case OBJECTS_ERROR: |
---|
80 | return RTEMS_INVALID_ID; |
---|
81 | |
---|
82 | case OBJECTS_LOCAL: |
---|
83 | if ( _Options_Is_no_wait( option_set ) ) |
---|
84 | wait = FALSE; |
---|
85 | else |
---|
86 | wait = TRUE; |
---|
87 | |
---|
88 | _CORE_message_queue_Seize( |
---|
89 | &the_message_queue->message_queue, |
---|
90 | the_message_queue->Object.id, |
---|
91 | buffer, |
---|
92 | size, |
---|
93 | wait, |
---|
94 | timeout |
---|
95 | ); |
---|
96 | _Thread_Enable_dispatch(); |
---|
97 | return( _Message_queue_Translate_core_message_queue_return_code( |
---|
98 | _Thread_Executing->Wait.return_code ) ); |
---|
99 | |
---|
100 | } |
---|
101 | |
---|
102 | return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ |
---|
103 | } |
---|