source: rtems/cpukit/score/src/coremsgflushsupp.c @ 721fe34

4.11
Last change on this file since 721fe34 was 721fe34, checked in by Joel Sherrill <joel.sherrill@…>, on May 31, 2012 at 8:34:36 PM

Fix C files which had two semi-colons at EOL

  • Property mode set to 100644
File size: 3.6 KB
Line 
1/*
2 *  CORE Message Queue Handler
3 *
4 *  DESCRIPTION:
5 *
6 *  This package is the implementation of the CORE Message Queue Handler.
7 *  This core object provides task synchronization and communication functions
8 *  via messages passed to queue objects.
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.com/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/object.h>
26#include <rtems/score/coremsg.h>
27#include <rtems/score/states.h>
28#include <rtems/score/thread.h>
29#include <rtems/score/wkspace.h>
30
31/*
32 *  _CORE_message_queue_Flush_support
33 *
34 *  This message handler routine removes all messages from a message queue
35 *  and returns them to the inactive message pool.  The number of messages
36 *  flushed from the queue is returned
37 *
38 *  Input parameters:
39 *    the_message_queue - pointer to message queue
40 *
41 *  Output parameters:
42 *    returns - number of messages placed on inactive chain
43 *
44 *  INTERRUPT LATENCY:
45 *    only case
46 */
47
48uint32_t   _CORE_message_queue_Flush_support(
49  CORE_message_queue_Control *the_message_queue
50)
51{
52  ISR_Level   level;
53  Chain_Node *inactive_head;
54  Chain_Node *inactive_first;
55  Chain_Node *message_queue_first;
56  Chain_Node *message_queue_last;
57  uint32_t    count;
58
59  /*
60   *  Currently, RTEMS supports no API that has both flush and blocking
61   *  sends.  Thus, this routine assumes that there are no senders
62   *  blocked waiting to send messages.  In the event, that an API is
63   *  added that can flush a message queue when threads are blocked
64   *  waiting to send, there are two basic behaviors envisioned:
65   *
66   *  (1) The thread queue of pending senders is a logical extension
67   *  of the pending message queue.  In this case, it should be
68   *  flushed using the _Thread_queue_Flush() service with a status
69   *  such as CORE_MESSAGE_QUEUE_SENDER_FLUSHED (which currently does
70   *  not exist).  This can be implemented without changing the "big-O"
71   *  of the message flushing part of the routine.
72   *
73   *  (2) Only the actual messages queued should be purged.  In this case,
74   *  the blocked sender threads must be allowed to send their messages.
75   *  In this case, the implementation will be forced to individually
76   *  dequeue the senders and queue their messages.  This will force
77   *  this routine to have "big O(n)" where n is the number of blocked
78   *  senders.  If there are more messages pending than senders blocked,
79   *  then the existing flush code can be used to dispose of the remaining
80   *  pending messages.
81   *
82   *  For now, though, we are very happy to have a small routine with
83   *  fixed execution time that only deals with pending messages.
84   */
85
86  _ISR_Disable( level );
87    inactive_head = _Chain_Head( &the_message_queue->Inactive_messages );
88    inactive_first = inactive_head->next;
89    message_queue_first = _Chain_First( &the_message_queue->Pending_messages );
90    message_queue_last = _Chain_Last( &the_message_queue->Pending_messages );
91
92    inactive_head->next = message_queue_first;
93    message_queue_last->next = inactive_first;
94    inactive_first->previous = message_queue_last;
95    message_queue_first->previous = inactive_head;
96
97    _Chain_Initialize_empty( &the_message_queue->Pending_messages );
98
99    count = the_message_queue->number_of_pending_messages;
100    the_message_queue->number_of_pending_messages = 0;
101  _ISR_Enable( level );
102  return count;
103}
Note: See TracBrowser for help on using the repository browser.