source: rtems/cpukit/score/src/coremsgflush.c @ c654b525

4.11
Last change on this file since c654b525 was c654b525, checked in by Sebastian Huber <sebastian.huber@…>, on Apr 30, 2015 at 11:18:45 AM

score: Delete _CORE_message_queue_Flush_support()

Check the number of pending messages in _CORE_message_queue_Flush() to
avoid race conditions.

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