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

5
Last change on this file since dafa5d88 was cc18d7b, checked in by Sebastian Huber <sebastian.huber@…>, on 04/30/15 at 11:12:54

score: Fine grained locking for message queues

Aggregate several critical sections into a bigger one. Sending and
receiving messages is now protected by an ISR lock. Thread dispatching
is only disabled in case a blocking operation is necessary. The message
copy procedure is done inside the critical section (interrupts
disabled). Thus this change may have a negative impact on the interrupt
latency in case very large messages are transferred.

Update #2273.

  • 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  ISR_lock_Context           *lock_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() 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, lock_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, lock_context );
82  return count;
83}
Note: See TracBrowser for help on using the repository browser.