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

5
Last change on this file since fce900b5 was 631b3c8, checked in by Sebastian Huber <sebastian.huber@…>, on 05/23/16 at 09:40:18

score: Move thread queue MP callout to context

Drop the multiprocessing (MP) dependent callout parameter from the
thread queue extract, dequeue, flush and unblock methods. Merge this
parameter with the lock context into new structure Thread_queue_Context.
This helps to gets rid of the conditionally compiled method call
helpers.

  • Property mode set to 100644
File size: 2.9 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
24uint32_t   _CORE_message_queue_Flush(
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}
Note: See TracBrowser for help on using the repository browser.