1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief RTEMS Message Queue Get Number Pending |
---|
5 | * @ingroup ClassicMessageQueue Message Queues |
---|
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/sysstate.h> |
---|
23 | #include <rtems/score/chain.h> |
---|
24 | #include <rtems/score/isr.h> |
---|
25 | #include <rtems/score/coremsg.h> |
---|
26 | #include <rtems/score/object.h> |
---|
27 | #include <rtems/score/states.h> |
---|
28 | #include <rtems/score/thread.h> |
---|
29 | #include <rtems/score/wkspace.h> |
---|
30 | #if defined(RTEMS_MULTIPROCESSING) |
---|
31 | #include <rtems/score/mpci.h> |
---|
32 | #endif |
---|
33 | #include <rtems/rtems/status.h> |
---|
34 | #include <rtems/rtems/attr.h> |
---|
35 | #include <rtems/rtems/messageimpl.h> |
---|
36 | #include <rtems/rtems/options.h> |
---|
37 | #include <rtems/rtems/support.h> |
---|
38 | |
---|
39 | /* |
---|
40 | * rtems_message_queue_get_number_pending |
---|
41 | * |
---|
42 | * This directive returns the number of messages pending. |
---|
43 | * |
---|
44 | * Input parameters: |
---|
45 | * id - queue id |
---|
46 | * count - return area for count |
---|
47 | * |
---|
48 | * Output parameters: |
---|
49 | * count - number of messages removed ( 0 = empty queue ) |
---|
50 | * RTEMS_SUCCESSFUL - if successful |
---|
51 | * error code - if unsuccessful |
---|
52 | */ |
---|
53 | |
---|
54 | rtems_status_code rtems_message_queue_get_number_pending( |
---|
55 | rtems_id id, |
---|
56 | uint32_t *count |
---|
57 | ) |
---|
58 | { |
---|
59 | register Message_queue_Control *the_message_queue; |
---|
60 | Objects_Locations location; |
---|
61 | |
---|
62 | if ( !count ) |
---|
63 | return RTEMS_INVALID_ADDRESS; |
---|
64 | |
---|
65 | the_message_queue = _Message_queue_Get( id, &location ); |
---|
66 | switch ( location ) { |
---|
67 | |
---|
68 | case OBJECTS_LOCAL: |
---|
69 | *count = the_message_queue->message_queue.number_of_pending_messages; |
---|
70 | _Objects_Put( &the_message_queue->Object ); |
---|
71 | return RTEMS_SUCCESSFUL; |
---|
72 | |
---|
73 | #if defined(RTEMS_MULTIPROCESSING) |
---|
74 | case OBJECTS_REMOTE: |
---|
75 | _Thread_Executing->Wait.return_argument = count; |
---|
76 | |
---|
77 | return _Message_queue_MP_Send_request_packet( |
---|
78 | MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_REQUEST, |
---|
79 | id, |
---|
80 | 0, /* buffer not used */ |
---|
81 | 0, /* size */ |
---|
82 | 0, /* option_set not used */ |
---|
83 | MPCI_DEFAULT_TIMEOUT |
---|
84 | ); |
---|
85 | #endif |
---|
86 | |
---|
87 | case OBJECTS_ERROR: |
---|
88 | break; |
---|
89 | } |
---|
90 | |
---|
91 | return RTEMS_INVALID_ID; |
---|
92 | } |
---|