[PATCH 23/45] score: Delete _CORE_message_queue_Flush_support()

Sebastian Huber sebastian.huber at embedded-brains.de
Fri May 15 11:41:23 UTC 2015


Check the number of pending messages in _CORE_message_queue_Flush() to
avoid race conditions.
---
 cpukit/score/Makefile.am                       |  2 +-
 cpukit/score/include/rtems/score/coremsgimpl.h | 17 ------
 cpukit/score/src/coremsgclose.c                |  3 +-
 cpukit/score/src/coremsgflush.c                | 72 ++++++++++++++++++----
 cpukit/score/src/coremsgflushsupp.c            | 84 --------------------------
 5 files changed, 62 insertions(+), 116 deletions(-)
 delete mode 100644 cpukit/score/src/coremsgflushsupp.c

diff --git a/cpukit/score/Makefile.am b/cpukit/score/Makefile.am
index 19d3237..6d4414c 100644
--- a/cpukit/score/Makefile.am
+++ b/cpukit/score/Makefile.am
@@ -158,7 +158,7 @@ libscore_a_SOURCES += src/corebarrier.c src/corebarrierrelease.c \
 ## CORE_MESSAGE_QUEUE_C_FILES
 libscore_a_SOURCES += src/coremsg.c src/coremsgbroadcast.c \
     src/coremsgclose.c src/coremsgflush.c src/coremsgflushwait.c \
-    src/coremsginsert.c src/coremsgflushsupp.c src/coremsgseize.c \
+    src/coremsginsert.c src/coremsgseize.c \
     src/coremsgsubmit.c
 
 ## CORE_MUTEX_C_FILES
diff --git a/cpukit/score/include/rtems/score/coremsgimpl.h b/cpukit/score/include/rtems/score/coremsgimpl.h
index cedf276..1f67969 100644
--- a/cpukit/score/include/rtems/score/coremsgimpl.h
+++ b/cpukit/score/include/rtems/score/coremsgimpl.h
@@ -179,23 +179,6 @@ uint32_t   _CORE_message_queue_Flush(
   CORE_message_queue_Control *the_message_queue
 );
 
-/**
- *  @brief Flush all outstanding messages.
- *
- *  This routine flushes all outstanding messages and returns
- *  them to the inactive message chain.
- *
- *  @param[in] the_message_queue points to the message queue to flush
- *
- *  @retval This method returns the number of pending messages flushed.
- *
- *  - INTERRUPT LATENCY:
- *    + single case
- */
-uint32_t   _CORE_message_queue_Flush_support(
-  CORE_message_queue_Control *the_message_queue
-);
-
 #if defined(FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API)
 /**
  *  @brief Flush waiting threads.
diff --git a/cpukit/score/src/coremsgclose.c b/cpukit/score/src/coremsgclose.c
index a4d0d84..437bf33 100644
--- a/cpukit/score/src/coremsgclose.c
+++ b/cpukit/score/src/coremsgclose.c
@@ -49,8 +49,7 @@ void _CORE_message_queue_Close(
    *  the flush satisfying any blocked senders as a side-effect.
    */
 
-  if ( the_message_queue->number_of_pending_messages != 0 )
-    (void) _CORE_message_queue_Flush_support( the_message_queue );
+  (void) _CORE_message_queue_Flush( the_message_queue );
 
   (void) _Workspace_Free( the_message_queue->message_buffers );
 
diff --git a/cpukit/score/src/coremsgflush.c b/cpukit/score/src/coremsgflush.c
index 51f6c8d..05683f0 100644
--- a/cpukit/score/src/coremsgflush.c
+++ b/cpukit/score/src/coremsgflush.c
@@ -1,8 +1,9 @@
 /**
- *  @file
+ * @file
  *
- *  @brief Flush Pending Messages
- *  @ingroup ScoreMessageQueue
+ * @brief Flush Messages Routine
+ *
+ * @ingroup ScoreMessageQueue
  */
 
 /*
@@ -18,19 +19,66 @@
 #include "config.h"
 #endif
 
-#include <rtems/system.h>
-#include <rtems/score/chain.h>
-#include <rtems/score/isr.h>
 #include <rtems/score/coremsgimpl.h>
-#include <rtems/score/thread.h>
-#include <rtems/score/wkspace.h>
+#include <rtems/score/isr.h>
 
 uint32_t   _CORE_message_queue_Flush(
   CORE_message_queue_Control *the_message_queue
 )
 {
-  if ( the_message_queue->number_of_pending_messages != 0 )
-    return _CORE_message_queue_Flush_support( the_message_queue );
-  else
-    return 0;
+  ISR_Level   level;
+  Chain_Node *inactive_head;
+  Chain_Node *inactive_first;
+  Chain_Node *message_queue_first;
+  Chain_Node *message_queue_last;
+  uint32_t    count;
+
+  /*
+   *  Currently, RTEMS supports no API that has both flush and blocking
+   *  sends.  Thus, this routine assumes that there are no senders
+   *  blocked waiting to send messages.  In the event, that an API is
+   *  added that can flush a message queue when threads are blocked
+   *  waiting to send, there are two basic behaviors envisioned:
+   *
+   *  (1) The thread queue of pending senders is a logical extension
+   *  of the pending message queue.  In this case, it should be
+   *  flushed using the _Thread_queue_Flush() service with a status
+   *  such as CORE_MESSAGE_QUEUE_SENDER_FLUSHED (which currently does
+   *  not exist).  This can be implemented without changing the "big-O"
+   *  of the message flushing part of the routine.
+   *
+   *  (2) Only the actual messages queued should be purged.  In this case,
+   *  the blocked sender threads must be allowed to send their messages.
+   *  In this case, the implementation will be forced to individually
+   *  dequeue the senders and queue their messages.  This will force
+   *  this routine to have "big O(n)" where n is the number of blocked
+   *  senders.  If there are more messages pending than senders blocked,
+   *  then the existing flush code can be used to dispose of the remaining
+   *  pending messages.
+   *
+   *  For now, though, we are very happy to have a small routine with
+   *  fixed execution time that only deals with pending messages.
+   */
+
+  _ISR_Disable( level );
+
+  count = the_message_queue->number_of_pending_messages;
+  if ( count != 0 ) {
+    the_message_queue->number_of_pending_messages = 0;
+
+    inactive_head = _Chain_Head( &the_message_queue->Inactive_messages );
+    inactive_first = inactive_head->next;
+    message_queue_first = _Chain_First( &the_message_queue->Pending_messages );
+    message_queue_last = _Chain_Last( &the_message_queue->Pending_messages );
+
+    inactive_head->next = message_queue_first;
+    message_queue_last->next = inactive_first;
+    inactive_first->previous = message_queue_last;
+    message_queue_first->previous = inactive_head;
+
+    _Chain_Initialize_empty( &the_message_queue->Pending_messages );
+  }
+
+  _ISR_Enable( level );
+  return count;
 }
diff --git a/cpukit/score/src/coremsgflushsupp.c b/cpukit/score/src/coremsgflushsupp.c
deleted file mode 100644
index 041972f..0000000
--- a/cpukit/score/src/coremsgflushsupp.c
+++ /dev/null
@@ -1,84 +0,0 @@
-/**
- * @file
- *
- * @brief Flush Messages Support Routine
- *
- * @ingroup ScoreMessageQueue
- */
-
-/*
- *  COPYRIGHT (c) 1989-1999.
- *  On-Line Applications Research Corporation (OAR).
- *
- *  The license and distribution terms for this file may be
- *  found in the file LICENSE in this distribution or at
- *  http://www.rtems.org/license/LICENSE.
- */
-
-#if HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <rtems/system.h>
-#include <rtems/score/chain.h>
-#include <rtems/score/isr.h>
-#include <rtems/score/coremsgimpl.h>
-#include <rtems/score/thread.h>
-#include <rtems/score/wkspace.h>
-
-uint32_t   _CORE_message_queue_Flush_support(
-  CORE_message_queue_Control *the_message_queue
-)
-{
-  ISR_Level   level;
-  Chain_Node *inactive_head;
-  Chain_Node *inactive_first;
-  Chain_Node *message_queue_first;
-  Chain_Node *message_queue_last;
-  uint32_t    count;
-
-  /*
-   *  Currently, RTEMS supports no API that has both flush and blocking
-   *  sends.  Thus, this routine assumes that there are no senders
-   *  blocked waiting to send messages.  In the event, that an API is
-   *  added that can flush a message queue when threads are blocked
-   *  waiting to send, there are two basic behaviors envisioned:
-   *
-   *  (1) The thread queue of pending senders is a logical extension
-   *  of the pending message queue.  In this case, it should be
-   *  flushed using the _Thread_queue_Flush() service with a status
-   *  such as CORE_MESSAGE_QUEUE_SENDER_FLUSHED (which currently does
-   *  not exist).  This can be implemented without changing the "big-O"
-   *  of the message flushing part of the routine.
-   *
-   *  (2) Only the actual messages queued should be purged.  In this case,
-   *  the blocked sender threads must be allowed to send their messages.
-   *  In this case, the implementation will be forced to individually
-   *  dequeue the senders and queue their messages.  This will force
-   *  this routine to have "big O(n)" where n is the number of blocked
-   *  senders.  If there are more messages pending than senders blocked,
-   *  then the existing flush code can be used to dispose of the remaining
-   *  pending messages.
-   *
-   *  For now, though, we are very happy to have a small routine with
-   *  fixed execution time that only deals with pending messages.
-   */
-
-  _ISR_Disable( level );
-    inactive_head = _Chain_Head( &the_message_queue->Inactive_messages );
-    inactive_first = inactive_head->next;
-    message_queue_first = _Chain_First( &the_message_queue->Pending_messages );
-    message_queue_last = _Chain_Last( &the_message_queue->Pending_messages );
-
-    inactive_head->next = message_queue_first;
-    message_queue_last->next = inactive_first;
-    inactive_first->previous = message_queue_last;
-    message_queue_first->previous = inactive_head;
-
-    _Chain_Initialize_empty( &the_message_queue->Pending_messages );
-
-    count = the_message_queue->number_of_pending_messages;
-    the_message_queue->number_of_pending_messages = 0;
-  _ISR_Enable( level );
-  return count;
-}
-- 
1.8.4.5




More information about the devel mailing list