From cbd07e4ce0ede36bacf6920bd594579e931b1bdd Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Fri, 21 Dec 2012 09:50:15 +0100 Subject: 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 ++++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+) create mode 100644 cpukit/score/src/chainnodecount.c (limited to 'cpukit') 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 #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 + * + * + * 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 + +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; +} -- cgit v1.2.3