RTEMS
coremsgflush.c
Go to the documentation of this file.
1 
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 #ifdef HAVE_CONFIG_H
19 #include "config.h"
20 #endif
21 
23 
25  CORE_message_queue_Control *the_message_queue,
26  Thread_queue_Context *queue_context
27 )
28 {
29  Chain_Node *inactive_head;
30  Chain_Node *inactive_first;
31  Chain_Node *message_queue_first;
32  Chain_Node *message_queue_last;
33  uint32_t count;
34 
35  /*
36  * Currently, RTEMS supports no API that has both flush and blocking
37  * sends. Thus, this routine assumes that there are no senders
38  * blocked waiting to send messages. In the event, that an API is
39  * added that can flush a message queue when threads are blocked
40  * waiting to send, there are two basic behaviors envisioned:
41  *
42  * (1) The thread queue of pending senders is a logical extension
43  * of the pending message queue. In this case, it should be
44  * flushed using the _Thread_queue_Flush_critical() service with a status
45  * such as CORE_MESSAGE_QUEUE_SENDER_FLUSHED (which currently does
46  * not exist). This can be implemented without changing the "big-O"
47  * of the message flushing part of the routine.
48  *
49  * (2) Only the actual messages queued should be purged. In this case,
50  * the blocked sender threads must be allowed to send their messages.
51  * In this case, the implementation will be forced to individually
52  * dequeue the senders and queue their messages. This will force
53  * this routine to have "big O(n)" where n is the number of blocked
54  * senders. If there are more messages pending than senders blocked,
55  * then the existing flush code can be used to dispose of the remaining
56  * pending messages.
57  *
58  * For now, though, we are very happy to have a small routine with
59  * fixed execution time that only deals with pending messages.
60  */
61 
62  _CORE_message_queue_Acquire_critical( the_message_queue, queue_context );
63 
64  count = the_message_queue->number_of_pending_messages;
65  if ( count != 0 ) {
66  the_message_queue->number_of_pending_messages = 0;
67 
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 
81  _CORE_message_queue_Release( the_message_queue, queue_context );
82  return count;
83 }
static __inline__ Chain_Node * _Chain_First(const Chain_Control *the_chain)
Returns pointer to chain's first node.
Definition: chainimpl.h:260
Chain_Node * previous
Definition: chain.h:72
Thread queue context for the thread queue methods.
Definition: threadq.h:198
Inlined Routines in the Core Message Handler.
Chain_Control Inactive_messages
Definition: coremsg.h:146
uint32_t _CORE_message_queue_Flush(CORE_message_queue_Control *the_message_queue, Thread_queue_Context *queue_context)
Flushes pending messages.
Definition: coremsgflush.c:24
uint32_t number_of_pending_messages
Definition: coremsg.h:113
Chain_Node * next
Definition: chain.h:70
static __inline__ Chain_Node * _Chain_Head(Chain_Control *the_chain)
Returns pointer to chain head.
Definition: chainimpl.h:195
Chain_Control Pending_messages
Definition: coremsg.h:121
static __inline__ void _Chain_Initialize_empty(Chain_Control *the_chain)
Initializes this chain as empty.
Definition: chainimpl.h:505
Control block used to manage each message queue.
Definition: coremsg.h:96
static __inline__ Chain_Node * _Chain_Last(const Chain_Control *the_chain)
Returns pointer to chain's last node.
Definition: chainimpl.h:294
static __inline__ void _CORE_message_queue_Release(CORE_message_queue_Control *the_message_queue, Thread_queue_Context *queue_context)
Releases the message queue.
Definition: coremsgimpl.h:446
static __inline__ void _CORE_message_queue_Acquire_critical(CORE_message_queue_Control *the_message_queue, Thread_queue_Context *queue_context)
Acquires the message queue critical.
Definition: coremsgimpl.h:432