[rtems commit] score: Add rtems_chain_node_count_unprotected()

Sebastian Huber sebh at rtems.org
Fri Dec 21 15:07:42 UTC 2012


Module:    rtems
Branch:    master
Commit:    cbd07e4ce0ede36bacf6920bd594579e931b1bdd
Changeset: http://git.rtems.org/rtems/commit/?id=cbd07e4ce0ede36bacf6920bd594579e931b1bdd

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Fri Dec 21 09:50:15 2012 +0100

score: Add rtems_chain_node_count_unprotected()

---

 cpukit/sapi/inline/rtems/chain.inl       |   17 +++++++++++++++
 cpukit/score/Makefile.am                 |    1 +
 cpukit/score/include/rtems/score/chain.h |   12 ++++++++++
 cpukit/score/src/chainnodecount.c        |   34 ++++++++++++++++++++++++++++++
 doc/user/chains.t                        |   28 ++++++++++++++++++++++++
 testsuites/sptests/spchain/init.c        |   22 ++++++++++++++++++-
 testsuites/sptests/spchain/spchain.doc   |    1 +
 testsuites/sptests/spchain/spchain.scn   |    1 +
 8 files changed, 115 insertions(+), 1 deletions(-)

diff --git a/cpukit/sapi/inline/rtems/chain.inl b/cpukit/sapi/inline/rtems/chain.inl
index d7f7f71..a1bfc2f 100644
--- a/cpukit/sapi/inline/rtems/chain.inl
+++ b/cpukit/sapi/inline/rtems/chain.inl
@@ -645,6 +645,23 @@ RTEMS_INLINE_ROUTINE bool rtems_chain_get_with_empty_check(
   return _Chain_Get_with_empty_check( chain, node );
 }
 
+/**
+ * @brief Returns the node count of the chain.
+ *
+ * @param[in] chain The chain.
+ *
+ * @note It does NOT disable interrupts to ensure the atomicity of the
+ * operation.
+ *
+ * @return The node count of the chain.
+ */
+RTEMS_INLINE_ROUTINE size_t rtems_chain_node_count_unprotected(
+  const rtems_chain_control *chain
+)
+{
+  return _Chain_Node_count_unprotected( chain );
+}
+
 /** @} */
 
 #endif
diff --git a/cpukit/score/Makefile.am b/cpukit/score/Makefile.am
index cc252db..cc0cbd5 100644
--- a/cpukit/score/Makefile.am
+++ b/cpukit/score/Makefile.am
@@ -326,6 +326,7 @@ 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/chainnodecount.c \
     src/interr.c src/isr.c src/wkspace.c src/wkstringduplicate.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 ebb0f24..f0a837f 100644
--- a/cpukit/score/include/rtems/score/chain.h
+++ b/cpukit/score/include/rtems/score/chain.h
@@ -254,6 +254,18 @@ bool _Chain_Get_with_empty_check(
   Chain_Node **the_node
 );
 
+/**
+ * @brief Returns the node count of the chain.
+ *
+ * @param[in] chain The chain.
+ *
+ * @note It does NOT disable interrupts to ensure the atomicity of the
+ * operation.
+ *
+ * @return The node count of the chain.
+ */
+size_t _Chain_Node_count_unprotected( const Chain_Control *chain );
+
 #ifndef __RTEMS_APPLICATION__
 #include <rtems/score/chain.inl>
 #endif
diff --git a/cpukit/score/src/chainnodecount.c b/cpukit/score/src/chainnodecount.c
new file mode 100644
index 0000000..3b54d93
--- /dev/null
+++ b/cpukit/score/src/chainnodecount.c
@@ -0,0 +1,34 @@
+/*
+ * 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>
+
+size_t _Chain_Node_count_unprotected( const Chain_Control *chain )
+{
+  size_t            count = 0;
+  const Chain_Node *tail  = _Chain_Immutable_tail( chain );
+  const Chain_Node *node  = _Chain_Immutable_first( chain );
+
+  while ( node != tail ) {
+    ++count;
+
+    node = _Chain_Immutable_next( node );
+  }
+
+  return count;
+}
diff --git a/doc/user/chains.t b/doc/user/chains.t
index b422ee9..e5dffc2 100644
--- a/doc/user/chains.t
+++ b/doc/user/chains.t
@@ -28,6 +28,7 @@ provided by RTEMS is:
 @item @code{@value{DIRPREFIX}chain_is_first} - Is the Node the first in the chain ?
 @item @code{@value{DIRPREFIX}chain_is_last} - Is the Node the last in the chain ? 
 @item @code{@value{DIRPREFIX}chain_has_only_one_node} - Does the node have one node ?
+ at item @code{@value{DIRPREFIX}chain_node_count_unprotected} - Returns the node count of the chain (unprotected)
 @item @code{@value{DIRPREFIX}chain_is_head} - Is the node the head ?
 @item @code{@value{DIRPREFIX}chain_is_tail} - Is the node the tail ?
 @item @code{@value{DIRPREFIX}chain_extract} - Extract the node from the chain
@@ -500,6 +501,33 @@ This function returns @code{true} if there is only one node on the chain and
 @c
 @c
 @page
+ at subsection Returns the node count of the chain (unprotected)
+
+ at cindex chain only one node
+
+ at subheading CALLING SEQUENCE:
+
+ at ifset is-C
+ at findex @value{DIRPREFIX}chain_node_count_unprotected
+ at example
+size_t @value{DIRPREFIX}chain_node_count_unprotected(
+  const @value{DIRPREFIX}chain_control *the_chain
+);
+ at end example
+ at end ifset
+
+ at subheading RETURNS
+
+This function returns the node count of the chain.
+
+ at subheading DESCRIPTION:
+
+This function returns the node count of the chain.
+
+ at c
+ at c
+ at c
+ at page
 @subsection Is this Node the Chain Head ?
 
 @cindex chain is node the head
diff --git a/testsuites/sptests/spchain/init.c b/testsuites/sptests/spchain/init.c
index 00e2d77..f8d54b0 100644
--- a/testsuites/sptests/spchain/init.c
+++ b/testsuites/sptests/spchain/init.c
@@ -136,7 +136,6 @@ static void test_chain_with_notification(void)
   rtems_test_assert( sc == RTEMS_SUCCESSFUL );
   rtems_test_assert( p == &a );
 
-  puts( "INIT - Verify rtems_chain_prepend_with_notification" );
   puts( "INIT - Verify rtems_chain_get_with_notification" );
   rtems_chain_initialize_empty( &chain );
 
@@ -199,6 +198,26 @@ static void test_chain_with_empty_check(void)
   rtems_test_assert( p == &b );
 }
 
+static void test_chain_node_count(void)
+{
+  rtems_chain_control chain;
+  rtems_chain_node nodes[3];
+  size_t count;
+  size_t i;
+
+  puts( "INIT - Verify rtems_chain_node_count_unprotected" );
+
+  rtems_chain_initialize_empty( &chain );
+  count = rtems_chain_node_count_unprotected( &chain );
+  rtems_test_assert( count == 0 );
+
+  for (i = 0; i < RTEMS_ARRAY_SIZE( nodes ); ++i) {
+    rtems_chain_append_unprotected( &chain, &nodes[i] );
+    count = rtems_chain_node_count_unprotected( &chain );
+    rtems_test_assert( count == i + 1 );
+  }
+}
+
 rtems_task Init(
   rtems_task_argument ignored
 )
@@ -240,6 +259,7 @@ rtems_task Init(
   test_chain_get_with_wait();
   test_chain_control_layout();
   test_chain_control_initializer();
+  test_chain_node_count();
 
   puts( "*** END OF RTEMS CHAIN API TEST ***" );
   rtems_test_exit(0);
diff --git a/testsuites/sptests/spchain/spchain.doc b/testsuites/sptests/spchain/spchain.doc
index 119d42b..29c9d10 100644
--- a/testsuites/sptests/spchain/spchain.doc
+++ b/testsuites/sptests/spchain/spchain.doc
@@ -23,6 +23,7 @@ directives:
   rtems_chain_prepend_with_notification
   rtems_chain_get_with_notification
   rtems_chain_get_with_wait
+  rtems_chain_node_count_unprotected
 
 concepts:
 
diff --git a/testsuites/sptests/spchain/spchain.scn b/testsuites/sptests/spchain/spchain.scn
index 4b06949..9cf4d52 100644
--- a/testsuites/sptests/spchain/spchain.scn
+++ b/testsuites/sptests/spchain/spchain.scn
@@ -12,4 +12,5 @@ INIT - Verify rtems_chain_get_with_notification
 INIT - Verify rtems_chain_get_with_wait
 INIT - Verify rtems_chain_control layout
 INIT - Verify rtems_chain_control initializer
+INIT - Verify rtems_chain_node_count_unprotected
 *** END OF RTEMS CHAIN API TEST ***




More information about the vc mailing list