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

4.115
Last change on this file since e6f7f81 was b5d514f, checked in by Sebastian Huber <sebastian.huber@…>, on 07/18/13 at 13:35:23

score: Create message queue implementation header

Move implementation specific parts of coremsg.h and coremsg.inl into new
header file coremsgimpl.h. The coremsg.h contains now only the
application visible API.

  • Property mode set to 100644
File size: 3.0 KB
Line 
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.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/coremsgimpl.h>
27#include <rtems/score/states.h>
28#include <rtems/score/thread.h>
29#include <rtems/score/wkspace.h>
30
31uint32_t   _CORE_message_queue_Flush_support(
32  CORE_message_queue_Control *the_message_queue
33)
34{
35  ISR_Level   level;
36  Chain_Node *inactive_head;
37  Chain_Node *inactive_first;
38  Chain_Node *message_queue_first;
39  Chain_Node *message_queue_last;
40  uint32_t    count;
41
42  /*
43   *  Currently, RTEMS supports no API that has both flush and blocking
44   *  sends.  Thus, this routine assumes that there are no senders
45   *  blocked waiting to send messages.  In the event, that an API is
46   *  added that can flush a message queue when threads are blocked
47   *  waiting to send, there are two basic behaviors envisioned:
48   *
49   *  (1) The thread queue of pending senders is a logical extension
50   *  of the pending message queue.  In this case, it should be
51   *  flushed using the _Thread_queue_Flush() service with a status
52   *  such as CORE_MESSAGE_QUEUE_SENDER_FLUSHED (which currently does
53   *  not exist).  This can be implemented without changing the "big-O"
54   *  of the message flushing part of the routine.
55   *
56   *  (2) Only the actual messages queued should be purged.  In this case,
57   *  the blocked sender threads must be allowed to send their messages.
58   *  In this case, the implementation will be forced to individually
59   *  dequeue the senders and queue their messages.  This will force
60   *  this routine to have "big O(n)" where n is the number of blocked
61   *  senders.  If there are more messages pending than senders blocked,
62   *  then the existing flush code can be used to dispose of the remaining
63   *  pending messages.
64   *
65   *  For now, though, we are very happy to have a small routine with
66   *  fixed execution time that only deals with pending messages.
67   */
68
69  _ISR_Disable( level );
70    inactive_head = _Chain_Head( &the_message_queue->Inactive_messages );
71    inactive_first = inactive_head->next;
72    message_queue_first = _Chain_First( &the_message_queue->Pending_messages );
73    message_queue_last = _Chain_Last( &the_message_queue->Pending_messages );
74
75    inactive_head->next = message_queue_first;
76    message_queue_last->next = inactive_first;
77    inactive_first->previous = message_queue_last;
78    message_queue_first->previous = inactive_head;
79
80    _Chain_Initialize_empty( &the_message_queue->Pending_messages );
81
82    count = the_message_queue->number_of_pending_messages;
83    the_message_queue->number_of_pending_messages = 0;
84  _ISR_Enable( level );
85  return count;
86}
Note: See TracBrowser for help on using the repository browser.