1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Flush Messages Support Routine |
---|
5 | * |
---|
6 | * @ingroup ScoreMessageQueue |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * COPYRIGHT (c) 1989-1999. |
---|
11 | * On-Line Applications Research Corporation (OAR). |
---|
12 | * |
---|
13 | * The license and distribution terms for this file may be |
---|
14 | * found in the file LICENSE in this distribution or at |
---|
15 | * http://www.rtems.org/license/LICENSE. |
---|
16 | */ |
---|
17 | |
---|
18 | #if HAVE_CONFIG_H |
---|
19 | #include "config.h" |
---|
20 | #endif |
---|
21 | |
---|
22 | #include <rtems/system.h> |
---|
23 | #include <rtems/score/chain.h> |
---|
24 | #include <rtems/score/isr.h> |
---|
25 | #include <rtems/score/coremsgimpl.h> |
---|
26 | #include <rtems/score/thread.h> |
---|
27 | #include <rtems/score/wkspace.h> |
---|
28 | |
---|
29 | uint32_t _CORE_message_queue_Flush_support( |
---|
30 | CORE_message_queue_Control *the_message_queue |
---|
31 | ) |
---|
32 | { |
---|
33 | ISR_Level level; |
---|
34 | Chain_Node *inactive_head; |
---|
35 | Chain_Node *inactive_first; |
---|
36 | Chain_Node *message_queue_first; |
---|
37 | Chain_Node *message_queue_last; |
---|
38 | uint32_t count; |
---|
39 | |
---|
40 | /* |
---|
41 | * Currently, RTEMS supports no API that has both flush and blocking |
---|
42 | * sends. Thus, this routine assumes that there are no senders |
---|
43 | * blocked waiting to send messages. In the event, that an API is |
---|
44 | * added that can flush a message queue when threads are blocked |
---|
45 | * waiting to send, there are two basic behaviors envisioned: |
---|
46 | * |
---|
47 | * (1) The thread queue of pending senders is a logical extension |
---|
48 | * of the pending message queue. In this case, it should be |
---|
49 | * flushed using the _Thread_queue_Flush() service with a status |
---|
50 | * such as CORE_MESSAGE_QUEUE_SENDER_FLUSHED (which currently does |
---|
51 | * not exist). This can be implemented without changing the "big-O" |
---|
52 | * of the message flushing part of the routine. |
---|
53 | * |
---|
54 | * (2) Only the actual messages queued should be purged. In this case, |
---|
55 | * the blocked sender threads must be allowed to send their messages. |
---|
56 | * In this case, the implementation will be forced to individually |
---|
57 | * dequeue the senders and queue their messages. This will force |
---|
58 | * this routine to have "big O(n)" where n is the number of blocked |
---|
59 | * senders. If there are more messages pending than senders blocked, |
---|
60 | * then the existing flush code can be used to dispose of the remaining |
---|
61 | * pending messages. |
---|
62 | * |
---|
63 | * For now, though, we are very happy to have a small routine with |
---|
64 | * fixed execution time that only deals with pending messages. |
---|
65 | */ |
---|
66 | |
---|
67 | _ISR_Disable( level ); |
---|
68 | inactive_head = _Chain_Head( &the_message_queue->Inactive_messages ); |
---|
69 | inactive_first = inactive_head->next; |
---|
70 | message_queue_first = _Chain_First( &the_message_queue->Pending_messages ); |
---|
71 | message_queue_last = _Chain_Last( &the_message_queue->Pending_messages ); |
---|
72 | |
---|
73 | inactive_head->next = message_queue_first; |
---|
74 | message_queue_last->next = inactive_first; |
---|
75 | inactive_first->previous = message_queue_last; |
---|
76 | message_queue_first->previous = inactive_head; |
---|
77 | |
---|
78 | _Chain_Initialize_empty( &the_message_queue->Pending_messages ); |
---|
79 | |
---|
80 | count = the_message_queue->number_of_pending_messages; |
---|
81 | the_message_queue->number_of_pending_messages = 0; |
---|
82 | _ISR_Enable( level ); |
---|
83 | return count; |
---|
84 | } |
---|