summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2012-12-21 09:50:15 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2012-12-21 15:40:27 +0100
commitcbd07e4ce0ede36bacf6920bd594579e931b1bdd (patch)
tree716aba4b883d92fe7a8aab8338dc783ba04d812d
parentbsp/gen83xx: Add GPR_1 to register map (diff)
downloadrtems-cbd07e4ce0ede36bacf6920bd594579e931b1bdd.tar.bz2
score: Add rtems_chain_node_count_unprotected()
-rw-r--r--cpukit/sapi/inline/rtems/chain.inl17
-rw-r--r--cpukit/score/Makefile.am1
-rw-r--r--cpukit/score/include/rtems/score/chain.h12
-rw-r--r--cpukit/score/src/chainnodecount.c34
-rw-r--r--doc/user/chains.t28
-rw-r--r--testsuites/sptests/spchain/init.c22
-rw-r--r--testsuites/sptests/spchain/spchain.doc1
-rw-r--r--testsuites/sptests/spchain/spchain.scn1
8 files changed, 115 insertions, 1 deletions
diff --git a/cpukit/sapi/inline/rtems/chain.inl b/cpukit/sapi/inline/rtems/chain.inl
index d7f7f7152d..a1bfc2f32e 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 cc252db0b9..cc0cbd5c35 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 ebb0f24e8c..f0a837f379 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 0000000000..3b54d93468
--- /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@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 b422ee91ce..e5dffc24df 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 ?
+@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
+@subsection Returns the node count of the chain (unprotected)
+
+@cindex chain only one node
+
+@subheading CALLING SEQUENCE:
+
+@ifset is-C
+@findex @value{DIRPREFIX}chain_node_count_unprotected
+@example
+size_t @value{DIRPREFIX}chain_node_count_unprotected(
+ const @value{DIRPREFIX}chain_control *the_chain
+);
+@end example
+@end ifset
+
+@subheading RETURNS
+
+This function returns the node count of the chain.
+
+@subheading DESCRIPTION:
+
+This function returns the node count of the chain.
+
+@c
+@c
+@c
+@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 00e2d778b6..f8d54b0fa4 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 119d42baeb..29c9d1045c 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 4b06949bf6..9cf4d5212f 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 ***