summaryrefslogtreecommitdiffstats
path: root/cpukit/score
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2014-08-03 13:02:58 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2014-08-05 09:30:37 +0200
commit60fe374247eba365afb7f1a7055298af575434c7 (patch)
treec3323eaf5c6939c5c9e4fd64671a443dcd521150 /cpukit/score
parentAdd and use RTEMS_CONTAINER_OF() (diff)
downloadrtems-60fe374247eba365afb7f1a7055298af575434c7.tar.bz2
rbtree: Add and use RBTree_Compare_result
Diffstat (limited to 'cpukit/score')
-rw-r--r--cpukit/score/include/rtems/score/rbtree.h11
-rw-r--r--cpukit/score/include/rtems/score/rbtreeimpl.h8
-rw-r--r--cpukit/score/include/rtems/score/scheduleredfimpl.h2
-rw-r--r--cpukit/score/include/rtems/score/threadqimpl.h2
-rw-r--r--cpukit/score/src/rbtreefind.c4
-rw-r--r--cpukit/score/src/rbtreeinsert.c13
-rw-r--r--cpukit/score/src/scheduleredf.c2
-rw-r--r--cpukit/score/src/threadq.c2
8 files changed, 33 insertions, 11 deletions
diff --git a/cpukit/score/include/rtems/score/rbtree.h b/cpukit/score/include/rtems/score/rbtree.h
index d23808ffd4..aa84558721 100644
--- a/cpukit/score/include/rtems/score/rbtree.h
+++ b/cpukit/score/include/rtems/score/rbtree.h
@@ -90,6 +90,15 @@ typedef enum {
} RBTree_Direction;
/**
+ * @brief Integer type for compare results.
+ *
+ * The type is large enough to represent pointers and 32-bit signed integers.
+ *
+ * @see RBTree_Compare.
+ */
+typedef long RBTree_Compare_result;
+
+/**
* @brief Compares two red-black tree nodes.
*
* @param[in] first The first node.
@@ -102,7 +111,7 @@ typedef enum {
* @retval negative The key value of the first node is less than the one of the
* second node.
*/
-typedef int ( *RBTree_Compare )(
+typedef RBTree_Compare_result ( *RBTree_Compare )(
const RBTree_Node *first,
const RBTree_Node *second
);
diff --git a/cpukit/score/include/rtems/score/rbtreeimpl.h b/cpukit/score/include/rtems/score/rbtreeimpl.h
index f3af7fe6ec..451b5f453a 100644
--- a/cpukit/score/include/rtems/score/rbtreeimpl.h
+++ b/cpukit/score/include/rtems/score/rbtreeimpl.h
@@ -144,20 +144,22 @@ RTEMS_INLINE_ROUTINE RBTree_Node *_RBTree_Parent_sibling(
return _RBTree_Sibling(the_node->parent);
}
-RTEMS_INLINE_ROUTINE bool _RBTree_Is_equal( int compare_result )
+RTEMS_INLINE_ROUTINE bool _RBTree_Is_equal(
+ RBTree_Compare_result compare_result
+)
{
return compare_result == 0;
}
RTEMS_INLINE_ROUTINE bool _RBTree_Is_greater(
- int compare_result
+ RBTree_Compare_result compare_result
)
{
return compare_result > 0;
}
RTEMS_INLINE_ROUTINE bool _RBTree_Is_lesser(
- int compare_result
+ RBTree_Compare_result compare_result
)
{
return compare_result < 0;
diff --git a/cpukit/score/include/rtems/score/scheduleredfimpl.h b/cpukit/score/include/rtems/score/scheduleredfimpl.h
index 50e40bc0eb..a98fb0f9c8 100644
--- a/cpukit/score/include/rtems/score/scheduleredfimpl.h
+++ b/cpukit/score/include/rtems/score/scheduleredfimpl.h
@@ -44,7 +44,7 @@ RTEMS_INLINE_ROUTINE Scheduler_EDF_Node *_Scheduler_EDF_Thread_get_node(
return (Scheduler_EDF_Node *) _Scheduler_Thread_get_node( the_thread );
}
-int _Scheduler_EDF_Compare(
+RBTree_Compare_result _Scheduler_EDF_Compare(
const RBTree_Node* n1,
const RBTree_Node* n2
);
diff --git a/cpukit/score/include/rtems/score/threadqimpl.h b/cpukit/score/include/rtems/score/threadqimpl.h
index 0e139cdbc6..5931d2252b 100644
--- a/cpukit/score/include/rtems/score/threadqimpl.h
+++ b/cpukit/score/include/rtems/score/threadqimpl.h
@@ -260,7 +260,7 @@ void _Thread_queue_Process_timeout(
* @retval 0 The @left node is of equal importance with @right node.
* @retval 1 The @left node is less important than @right node.
*/
-int _Thread_queue_Compare_priority(
+RBTree_Compare_result _Thread_queue_Compare_priority(
const RBTree_Node *left,
const RBTree_Node *right
);
diff --git a/cpukit/score/src/rbtreefind.c b/cpukit/score/src/rbtreefind.c
index f7676260dc..168a108962 100644
--- a/cpukit/score/src/rbtreefind.c
+++ b/cpukit/score/src/rbtreefind.c
@@ -30,8 +30,8 @@ RBTree_Node *_RBTree_Find(
RBTree_Node *found = NULL;
while ( iter_node != NULL ) {
- int compare_result = ( *compare )( the_node, iter_node );
- RBTree_Direction dir;
+ RBTree_Compare_result compare_result = ( *compare )( the_node, iter_node );
+ RBTree_Direction dir;
if ( _RBTree_Is_equal( compare_result ) ) {
found = iter_node;
diff --git a/cpukit/score/src/rbtreeinsert.c b/cpukit/score/src/rbtreeinsert.c
index afff1ef5f9..3bccba5aaa 100644
--- a/cpukit/score/src/rbtreeinsert.c
+++ b/cpukit/score/src/rbtreeinsert.c
@@ -12,6 +12,16 @@
#include <rtems/score/rbtreeimpl.h>
+RTEMS_STATIC_ASSERT(
+ sizeof( RBTree_Compare_result ) >= sizeof( intptr_t ),
+ RBTree_Compare_result_intptr_t
+);
+
+RTEMS_STATIC_ASSERT(
+ sizeof( RBTree_Compare_result ) >= sizeof( int32_t ),
+ RBTree_Compare_result_int32_t
+);
+
/** @brief Validate and fix-up tree properties for a new insert/colored node
*
* This routine checks and fixes the Red-Black Tree properties based on
@@ -77,7 +87,8 @@ RBTree_Node *_RBTree_Insert(
} else {
/* typical binary search tree insert, descend tree to leaf and insert */
while ( iter_node ) {
- int compare_result = ( *compare )( the_node, iter_node );
+ RBTree_Compare_result compare_result =
+ ( *compare )( the_node, iter_node );
if ( is_unique && _RBTree_Is_equal( compare_result ) )
return iter_node;
diff --git a/cpukit/score/src/scheduleredf.c b/cpukit/score/src/scheduleredf.c
index 6dfa288999..00b6181e59 100644
--- a/cpukit/score/src/scheduleredf.c
+++ b/cpukit/score/src/scheduleredf.c
@@ -20,7 +20,7 @@
#include <rtems/score/scheduleredfimpl.h>
-int _Scheduler_EDF_Compare(
+RBTree_Compare_result _Scheduler_EDF_Compare(
const RBTree_Node* n1,
const RBTree_Node* n2
)
diff --git a/cpukit/score/src/threadq.c b/cpukit/score/src/threadq.c
index b146ad410c..aa08541e93 100644
--- a/cpukit/score/src/threadq.c
+++ b/cpukit/score/src/threadq.c
@@ -24,7 +24,7 @@
#include <rtems/score/scheduler.h>
#include <rtems/score/threadimpl.h>
-int _Thread_queue_Compare_priority(
+RBTree_Compare_result _Thread_queue_Compare_priority(
const RBTree_Node *left,
const RBTree_Node *right
)