summaryrefslogtreecommitdiffstats
path: root/cpukit/score/src
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2011-08-21 20:07:11 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2011-08-21 20:07:11 +0000
commit74f1c73e969fe7a7b1ca53bb6fcb1336f4a179cb (patch)
tree4f2b74ad7cf7f1c661bdfd0cd89c284964ad2f64 /cpukit/score/src
parent2011-08-21 Joel Sherrill <joel.sherrilL@OARcorp.com> (diff)
downloadrtems-74f1c73e969fe7a7b1ca53bb6fcb1336f4a179cb.tar.bz2
2011-08-21 Petr Benes <benesp16@fel.cvut.cz>
PR 1886/cpukit * sapi/include/rtems/rbtree.h, sapi/inline/rtems/rbtree.inl, score/include/rtems/score/rbtree.h, score/inline/rtems/score/rbtree.inl, score/src/rbtree.c, score/src/rbtreeinsert.c: This patch enables inserting duplicate keys into rbtree. It is possible to turn on this feature when initializing the tree.
Diffstat (limited to 'cpukit/score/src')
-rw-r--r--cpukit/score/src/rbtree.c13
-rw-r--r--cpukit/score/src/rbtreeinsert.c9
2 files changed, 12 insertions, 10 deletions
diff --git a/cpukit/score/src/rbtree.c b/cpukit/score/src/rbtree.c
index eb3af773cb..e0fc560229 100644
--- a/cpukit/score/src/rbtree.c
+++ b/cpukit/score/src/rbtree.c
@@ -32,11 +32,12 @@
*/
void _RBTree_Initialize(
- RBTree_Control *the_rbtree,
- void *compare_function,
- void *starting_address,
- size_t number_nodes,
- size_t node_size
+ RBTree_Control *the_rbtree,
+ RBTree_Compare_function compare_function,
+ void *starting_address,
+ size_t number_nodes,
+ size_t node_size,
+ bool is_unique
)
{
size_t count;
@@ -46,7 +47,7 @@ void _RBTree_Initialize(
if (!the_rbtree) return;
/* could do sanity checks here */
- _RBTree_Initialize_empty(the_rbtree, compare_function);
+ _RBTree_Initialize_empty(the_rbtree, compare_function, is_unique);
count = number_nodes;
next = starting_address;
diff --git a/cpukit/score/src/rbtreeinsert.c b/cpukit/score/src/rbtreeinsert.c
index bb1915de54..1208a3c81a 100644
--- a/cpukit/score/src/rbtreeinsert.c
+++ b/cpukit/score/src/rbtreeinsert.c
@@ -72,7 +72,7 @@ void _RBTree_Validate_insert_unprotected(
* @retval 0 Successfully inserted.
* @retval -1 NULL @a the_node.
* @retval RBTree_Node* if one with equal key to the key of @a the_node exists
- * in @a the_rbtree.
+ * in an unique @a the_rbtree.
*
* @note It does NOT disable interrupts to ensure the atomicity
* of the extract operation.
@@ -97,7 +97,8 @@ RBTree_Node *_RBTree_Insert_unprotected(
/* typical binary search tree insert, descend tree to leaf and insert */
while (iter_node) {
compare_result = the_rbtree->compare_function(the_node, iter_node);
- if ( !compare_result ) return iter_node;
+ if ( the_rbtree->is_unique && !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;
@@ -138,7 +139,7 @@ RBTree_Node *_RBTree_Insert_unprotected(
* only case
*/
-void _RBTree_Insert(
+RBTree_Node *_RBTree_Insert(
RBTree_Control *tree,
RBTree_Node *node
)
@@ -146,6 +147,6 @@ void _RBTree_Insert(
ISR_Level level;
_ISR_Disable( level );
- _RBTree_Insert_unprotected( tree, node );
+ return _RBTree_Insert_unprotected( tree, node );
_ISR_Enable( level );
}