[PATCH 1/5] score: Add _Chain_Append_if_node_is_off_chain()

Sebastian Huber sebastian.huber at embedded-brains.de
Mon Dec 3 11:54:07 UTC 2012


---
 cpukit/score/Makefile.am                 |    3 +-
 cpukit/score/include/rtems/score/chain.h |   14 ++++++++++
 cpukit/score/src/chainappendifoffchain.c |   42 ++++++++++++++++++++++++++++++
 3 files changed, 58 insertions(+), 1 deletions(-)
 create mode 100644 cpukit/score/src/chainappendifoffchain.c

diff --git a/cpukit/score/Makefile.am b/cpukit/score/Makefile.am
index cc252db..c605829 100644
--- a/cpukit/score/Makefile.am
+++ b/cpukit/score/Makefile.am
@@ -326,7 +326,8 @@ libscore_a_SOURCES += src/userextaddset.c \
 libscore_a_SOURCES += src/apiext.c src/chain.c src/chainappend.c \
     src/chainextract.c src/chainget.c src/chaininsert.c \
     src/chainappendempty.c src/chainprependempty.c src/chaingetempty.c \
-    src/interr.c src/isr.c src/wkspace.c src/wkstringduplicate.c
+    src/interr.c src/isr.c src/wkspace.c src/wkstringduplicate.c \
+    src/chainappendifoffchain.c
 
 EXTRA_DIST = src/Unlimited.txt
 
diff --git a/cpukit/score/include/rtems/score/chain.h b/cpukit/score/include/rtems/score/chain.h
index 53976e6..dca2572 100644
--- a/cpukit/score/include/rtems/score/chain.h
+++ b/cpukit/score/include/rtems/score/chain.h
@@ -210,6 +210,20 @@ bool _Chain_Append_with_empty_check(
 );
 
 /**
+ *  @brief Append a node on the end of a chain if the node is in the off chain
+ *  state.
+ *
+ *  @note It disables interrupts to ensure the atomicity of the
+ *  append operation.
+ *
+ *  @see _Chain_Is_node_off_chain().
+ */
+void _Chain_Append_if_node_is_off_chain(
+  Chain_Control *the_chain,
+  Chain_Node    *the_node
+);
+
+/**
  * @brief Prepend a node and check if the chain was empty before.
  *
  * This routine prepends the_node onto the front of the_chain.
diff --git a/cpukit/score/src/chainappendifoffchain.c b/cpukit/score/src/chainappendifoffchain.c
new file mode 100644
index 0000000..0095aa0
--- /dev/null
+++ b/cpukit/score/src/chainappendifoffchain.c
@@ -0,0 +1,42 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreChain
+ *
+ * @brief _Chain_Append_if_node_is_off_chain() implementation.
+ */
+
+/*
+ * Copyright (c) 2012 embedded brains GmbH.  All rights reserved.
+ *
+ *  embedded brains GmbH
+ *  Obere Lagerstr. 30
+ *  82178 Puchheim
+ *  Germany
+ *  <rtems at embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#if HAVE_CONFIG_H
+  #include "config.h"
+#endif
+
+#include <rtems/score/chain.h>
+#include <rtems/score/isr.h>
+
+void _Chain_Append_if_node_is_off_chain(
+  Chain_Control *chain,
+  Chain_Node *node
+)
+{
+  ISR_Level level;
+
+  _ISR_Disable( level );
+  if ( _Chain_Is_node_off_chain( node ) ) {
+    _Chain_Append_unprotected( chain, node );
+  }
+  _ISR_Enable( level );
+}
-- 
1.7.7




More information about the devel mailing list