[rtems commit] score: Add and use CHAIN_INITIALIZER_ONE_NODE().

Sebastian Huber sebh at rtems.org
Tue Aug 27 08:44:49 UTC 2013


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Mon Aug 26 14:27:52 2013 +0200

score: Add and use CHAIN_INITIALIZER_ONE_NODE().

Add and use CHAIN_NODE_INITIALIZER_ONE_NODE_CHAIN(),
RTEMS_CHAIN_INITIALIZER_ONE_NODE() and
RTEMS_CHAIN_NODE_INITIALIZER_ONE_NODE_CHAIN().

---

 cpukit/libcsupport/src/__usrenv.c            |   19 ++++++-------------
 cpukit/sapi/include/rtems/chain.h            |   16 ++++++++++++++++
 cpukit/score/include/rtems/score/chainimpl.h |   16 ++++++++++++++++
 testsuites/sptests/spchain/init.c            |   26 ++++++++++++++++++++++++++
 4 files changed, 64 insertions(+), 13 deletions(-)

diff --git a/cpukit/libcsupport/src/__usrenv.c b/cpukit/libcsupport/src/__usrenv.c
index a0d96cb..8e9e8c1 100644
--- a/cpukit/libcsupport/src/__usrenv.c
+++ b/cpukit/libcsupport/src/__usrenv.c
@@ -218,15 +218,9 @@ static const rtems_filesystem_operations_table null_ops = {
 };
 
 rtems_filesystem_mount_table_entry_t rtems_filesystem_null_mt_entry = {
-  .location_chain = {
-    .Head = {
-      .Node = {
-        .next = &rtems_filesystem_global_location_null.location.mt_entry_node,
-        .previous = NULL
-      },
-      .fill = &rtems_filesystem_global_location_null.location.mt_entry_node,
-    }
-  },
+  .location_chain = RTEMS_CHAIN_INITIALIZER_ONE_NODE(
+    &rtems_filesystem_global_location_null.location.mt_entry_node
+  ),
   .ops = &null_ops,
   .mt_point_node = &rtems_filesystem_global_location_null,
   .mt_fs_root = &rtems_filesystem_global_location_null,
@@ -236,10 +230,9 @@ rtems_filesystem_mount_table_entry_t rtems_filesystem_null_mt_entry = {
 
 rtems_filesystem_global_location_t rtems_filesystem_global_location_null = {
   .location = {
-    .mt_entry_node = {
-      .next = &rtems_filesystem_null_mt_entry.location_chain.Tail.Node,
-      .previous = &rtems_filesystem_null_mt_entry.location_chain.Head.Node
-    },
+    .mt_entry_node = RTEMS_CHAIN_NODE_INITIALIZER_ONE_NODE_CHAIN(
+      &rtems_filesystem_null_mt_entry.location_chain
+    ),
     .handlers = &rtems_filesystem_null_handlers,
     .mt_entry = &rtems_filesystem_null_mt_entry
   },
diff --git a/cpukit/sapi/include/rtems/chain.h b/cpukit/sapi/include/rtems/chain.h
index b5808e4..7e48dc7 100644
--- a/cpukit/sapi/include/rtems/chain.h
+++ b/cpukit/sapi/include/rtems/chain.h
@@ -45,6 +45,22 @@ typedef Chain_Control rtems_chain_control;
   CHAIN_INITIALIZER_EMPTY(name)
 
 /**
+ *  @brief Chain initializer for a chain with one @a node.
+ *
+ *  @see RTEMS_CHAIN_NODE_INITIALIZER_ONE_NODE_CHAIN().
+ */
+#define RTEMS_CHAIN_INITIALIZER_ONE_NODE( node ) \
+  CHAIN_INITIALIZER_ONE_NODE( node )
+
+/**
+ *  @brief Chain node initializer for a @a chain containing exactly this node.
+ *
+ *  @see RTEMS_CHAIN_INITIALIZER_ONE_NODE().
+ */
+#define RTEMS_CHAIN_NODE_INITIALIZER_ONE_NODE_CHAIN( chain ) \
+  CHAIN_NODE_INITIALIZER_ONE_NODE_CHAIN( chain )
+
+/**
  *  @brief Chain definition for an empty chain with designator @a name.
  */
 #define RTEMS_CHAIN_DEFINE_EMPTY(name) \
diff --git a/cpukit/score/include/rtems/score/chainimpl.h b/cpukit/score/include/rtems/score/chainimpl.h
index f87ce82..98416b2 100644
--- a/cpukit/score/include/rtems/score/chainimpl.h
+++ b/cpukit/score/include/rtems/score/chainimpl.h
@@ -37,6 +37,22 @@ extern "C" {
   { { { &(name).Tail.Node, NULL }, &(name).Head.Node } }
 
 /**
+ *  @brief Chain initializer for a chain with one @a node.
+ *
+ *  @see CHAIN_NODE_INITIALIZER_ONE_NODE_CHAIN().
+ */
+#define CHAIN_INITIALIZER_ONE_NODE( node ) \
+  { { { (node), NULL }, (node) } }
+
+/**
+ *  @brief Chain node initializer for a @a chain containing exactly this node.
+ *
+ *  @see CHAIN_INITIALIZER_ONE_NODE().
+ */
+#define CHAIN_NODE_INITIALIZER_ONE_NODE_CHAIN( chain ) \
+  { &(chain)->Tail.Node, &(chain)->Head.Node }
+
+/**
  *  @brief Chain definition for an empty chain with designator @a name.
  */
 #define CHAIN_DEFINE_EMPTY(name) \
diff --git a/testsuites/sptests/spchain/init.c b/testsuites/sptests/spchain/init.c
index 72895b6..219d0f3 100644
--- a/testsuites/sptests/spchain/init.c
+++ b/testsuites/sptests/spchain/init.c
@@ -25,11 +25,37 @@ typedef struct {
   int              id;
 } test_node;
 
+static rtems_chain_control one_node_chain;
+
+static rtems_chain_node node_of_one_node_chain =
+  RTEMS_CHAIN_NODE_INITIALIZER_ONE_NODE_CHAIN( &one_node_chain );
+
+static rtems_chain_control one_node_chain =
+  RTEMS_CHAIN_INITIALIZER_ONE_NODE( &node_of_one_node_chain );
+
 static void test_chain_control_initializer(void)
 {
   rtems_chain_control chain = RTEMS_CHAIN_INITIALIZER_EMPTY( chain );
+
   puts( "INIT - Verify rtems_chain_control initializer" );
+
   rtems_test_assert( rtems_chain_is_empty( &chain ) );
+
+  rtems_test_assert( rtems_chain_has_only_one_node( &one_node_chain ) );
+  rtems_test_assert(
+    rtems_chain_immutable_first( &one_node_chain ) == &node_of_one_node_chain
+  );
+  rtems_test_assert(
+    rtems_chain_immutable_last( &one_node_chain ) == &node_of_one_node_chain
+  );
+  rtems_test_assert(
+    rtems_chain_immutable_head( &one_node_chain )
+      == rtems_chain_immutable_previous( &node_of_one_node_chain )
+  );
+  rtems_test_assert(
+    rtems_chain_immutable_tail( &one_node_chain )
+      == rtems_chain_immutable_next( &node_of_one_node_chain )
+  );
 }
 
 static void test_chain_control_layout(void)




More information about the vc mailing list