summaryrefslogtreecommitdiffstats
path: root/cpukit/score/src
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2011-08-02 19:25:59 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2011-08-02 19:25:59 +0000
commit13c4f853e6655e6b1c759255bea4f63c77806cdc (patch)
tree6347f845f2761b7ea2863c44c672e83f40177c9e /cpukit/score/src
parent2011-08-02 Ricardo Aguirre <el.mastin@ymail.com> (diff)
downloadrtems-13c4f853e6655e6b1c759255bea4f63c77806cdc.tar.bz2
2011-08-02 Joel Sherrill <joel.sherrill@oarcorp.com>
PR 1877/cpukit * libfs/src/imfs/imfs_mknod.c, libfs/src/imfs/memfile.c, sapi/inline/rtems/rbtree.inl, score/include/rtems/score/rbtree.h, score/inline/rtems/score/rbtree.inl, score/src/rbtree.c, score/src/rbtreefind.c, score/src/rbtreeinsert.c: Add comparison function for RBTrees.
Diffstat (limited to 'cpukit/score/src')
-rw-r--r--cpukit/score/src/rbtree.c3
-rw-r--r--cpukit/score/src/rbtreefind.c8
-rw-r--r--cpukit/score/src/rbtreeinsert.c8
3 files changed, 11 insertions, 8 deletions
diff --git a/cpukit/score/src/rbtree.c b/cpukit/score/src/rbtree.c
index 0b52989927..eb3af773cb 100644
--- a/cpukit/score/src/rbtree.c
+++ b/cpukit/score/src/rbtree.c
@@ -33,6 +33,7 @@
void _RBTree_Initialize(
RBTree_Control *the_rbtree,
+ void *compare_function,
void *starting_address,
size_t number_nodes,
size_t node_size
@@ -45,7 +46,7 @@ void _RBTree_Initialize(
if (!the_rbtree) return;
/* could do sanity checks here */
- _RBTree_Initialize_empty(the_rbtree);
+ _RBTree_Initialize_empty(the_rbtree, compare_function);
count = number_nodes;
next = starting_address;
diff --git a/cpukit/score/src/rbtreefind.c b/cpukit/score/src/rbtreefind.c
index 1002982342..904a5b87c8 100644
--- a/cpukit/score/src/rbtreefind.c
+++ b/cpukit/score/src/rbtreefind.c
@@ -21,11 +21,11 @@
* _RBTree_Find
*
* This kernel routine returns a pointer to the rbtree node containing the
- * given value within the given tree, if it exists, or NULL otherwise.
+ * given key within the given tree, if it exists, or NULL otherwise.
*
* Input parameters:
* the_rbtree - pointer to rbtree control
- * the_value - value of the node to search for
+ * search_node - node with the key to search for
*
* Output parameters:
* return_node - pointer to control header of rbtree
@@ -38,7 +38,7 @@
RBTree_Node *_RBTree_Find(
RBTree_Control *the_rbtree,
- unsigned int the_value
+ RBTree_Node *search_node
)
{
ISR_Level level;
@@ -46,7 +46,7 @@ RBTree_Node *_RBTree_Find(
return_node = NULL;
_ISR_Disable( level );
- return_node = _RBTree_Find_unprotected( the_rbtree, the_value );
+ return_node = _RBTree_Find_unprotected( the_rbtree, search_node );
_ISR_Enable( level );
return return_node;
}
diff --git a/cpukit/score/src/rbtreeinsert.c b/cpukit/score/src/rbtreeinsert.c
index 8a694063ff..bb1915de54 100644
--- a/cpukit/score/src/rbtreeinsert.c
+++ b/cpukit/score/src/rbtreeinsert.c
@@ -71,7 +71,7 @@ void _RBTree_Validate_insert_unprotected(
*
* @retval 0 Successfully inserted.
* @retval -1 NULL @a the_node.
- * @retval RBTree_Node* if one with equal value to @a the_node->value exists
+ * @retval RBTree_Node* if one with equal key to the key of @a the_node exists
* in @a the_rbtree.
*
* @note It does NOT disable interrupts to ensure the atomicity
@@ -85,6 +85,7 @@ RBTree_Node *_RBTree_Insert_unprotected(
if(!the_node) return (RBTree_Node*)-1;
RBTree_Node *iter_node = the_rbtree->root;
+ int compare_result;
if (!iter_node) { /* special case: first node inserted */
the_node->color = RBT_BLACK;
@@ -95,8 +96,9 @@ RBTree_Node *_RBTree_Insert_unprotected(
} else {
/* typical binary search tree insert, descend tree to leaf and insert */
while (iter_node) {
- if(the_node->value == iter_node->value) return(iter_node);
- RBTree_Direction dir = the_node->value > iter_node->value;
+ compare_result = the_rbtree->compare_function(the_node, iter_node);
+ if ( !compare_result ) return iter_node;
+ RBTree_Direction dir = (compare_result != -1);
if (!iter_node->child[dir]) {
the_node->child[RBT_LEFT] = the_node->child[RBT_RIGHT] = NULL;
the_node->color = RBT_RED;