source: rtems/cpukit/score/src/coremsgflushsupp.c @ a8eed23

4.104.114.84.95
Last change on this file since a8eed23 was a8eed23, checked in by Ralf Corsepius <ralf.corsepius@…>, on 01/27/05 at 05:57:05

Include config.h.

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