[PATCH 04/15] score: Add node adjust to _RBTree_Find_inline()

Sebastian Huber sebastian.huber at embedded-brains.de
Tue Apr 5 13:09:49 UTC 2016


---
 cpukit/posix/include/rtems/posix/keyimpl.h | 14 ++++++++++----
 cpukit/posix/src/keygetspecific.c          | 15 ++++++---------
 cpukit/posix/src/keysetspecific.c          | 29 +++++++++++++----------------
 cpukit/score/include/rtems/score/rbtree.h  | 12 ++++++++----
 4 files changed, 37 insertions(+), 33 deletions(-)

diff --git a/cpukit/posix/include/rtems/posix/keyimpl.h b/cpukit/posix/include/rtems/posix/keyimpl.h
index 7095a16..a534b7e 100644
--- a/cpukit/posix/include/rtems/posix/keyimpl.h
+++ b/cpukit/posix/include/rtems/posix/keyimpl.h
@@ -139,16 +139,22 @@ RTEMS_INLINE_ROUTINE bool _POSIX_Keys_Key_value_less(
   return *the_left < the_right->key;
 }
 
-RTEMS_INLINE_ROUTINE RBTree_Node *_POSIX_Keys_Key_value_find(
-  pthread_key_t     key,
-  Thread_Control   *the_thread
+RTEMS_INLINE_ROUTINE void *_POSIX_Keys_Key_value_adjust( RBTree_Node *node )
+{
+  return POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( node );
+}
+
+RTEMS_INLINE_ROUTINE POSIX_Keys_Key_value_pair *_POSIX_Keys_Key_value_find(
+  pthread_key_t   key,
+  Thread_Control *the_thread
 )
 {
   return _RBTree_Find_inline(
     &the_thread->Keys.Key_value_pairs,
     &key,
     _POSIX_Keys_Key_value_equal,
-    _POSIX_Keys_Key_value_less
+    _POSIX_Keys_Key_value_less,
+    _POSIX_Keys_Key_value_adjust
   );
 }
 
diff --git a/cpukit/posix/src/keygetspecific.c b/cpukit/posix/src/keygetspecific.c
index 08ac1ed..ae29955 100644
--- a/cpukit/posix/src/keygetspecific.c
+++ b/cpukit/posix/src/keygetspecific.c
@@ -30,20 +30,17 @@ void *pthread_getspecific(
   pthread_key_t  key
 )
 {
-  Thread_Control   *executing;
-  ISR_lock_Context  lock_context;
-  RBTree_Node      *node;
-  void             *value;
+  Thread_Control            *executing;
+  ISR_lock_Context           lock_context;
+  POSIX_Keys_Key_value_pair *key_value_pair;
+  void                      *value;
 
   executing = _Thread_Get_executing();
   _POSIX_Keys_Key_value_acquire( executing, &lock_context );
 
-  node = _POSIX_Keys_Key_value_find( key, executing );
+  key_value_pair = _POSIX_Keys_Key_value_find( key, executing );
 
-  if ( node != NULL ) {
-    POSIX_Keys_Key_value_pair *key_value_pair;
-
-    key_value_pair = POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( node );
+  if ( key_value_pair != NULL ) {
     value = key_value_pair->value;
   } else {
     value = NULL;
diff --git a/cpukit/posix/src/keysetspecific.c b/cpukit/posix/src/keysetspecific.c
index 8b0f517..7034d8e 100644
--- a/cpukit/posix/src/keysetspecific.c
+++ b/cpukit/posix/src/keysetspecific.c
@@ -24,11 +24,11 @@
 
 #include <errno.h>
 
-static int _POSIX_Keys_Set_value( RBTree_Node *node, const void *value )
+static int _POSIX_Keys_Set_value(
+  POSIX_Keys_Key_value_pair *key_value_pair,
+  const void                *value
+)
 {
-  POSIX_Keys_Key_value_pair *key_value_pair;
-
-  key_value_pair = POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( node );
   key_value_pair->value = RTEMS_DECONST( void *, value );
 
   return 0;
@@ -91,16 +91,13 @@ static int _POSIX_Keys_Delete_value(
 
   the_key = _POSIX_Keys_Get( key );
   if ( the_key != NULL ) {
-    ISR_lock_Context  lock_context;
-    RBTree_Node      *node;
+    POSIX_Keys_Key_value_pair *key_value_pair;
+    ISR_lock_Context           lock_context;
 
     _POSIX_Keys_Key_value_acquire( executing, &lock_context );
 
-    node = _POSIX_Keys_Key_value_find( key, executing );
-    if ( node != NULL ) {
-      POSIX_Keys_Key_value_pair *key_value_pair;
-
-      key_value_pair = POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( node );
+    key_value_pair = _POSIX_Keys_Key_value_find( key, executing );
+    if ( key_value_pair != NULL ) {
       _RBTree_Extract(
         &executing->Keys.Key_value_pairs,
         &key_value_pair->Lookup_node
@@ -138,14 +135,14 @@ int pthread_setspecific(
   executing = _Thread_Get_executing();
 
   if ( value != NULL ) {
-    ISR_lock_Context  lock_context;
-    RBTree_Node      *node;
+    ISR_lock_Context           lock_context;
+    POSIX_Keys_Key_value_pair *key_value_pair;
 
     _POSIX_Keys_Key_value_acquire( executing, &lock_context );
 
-    node = _POSIX_Keys_Key_value_find( key, executing );
-    if ( node != NULL ) {
-      eno = _POSIX_Keys_Set_value( node, value );
+    key_value_pair = _POSIX_Keys_Key_value_find( key, executing );
+    if ( key_value_pair != NULL ) {
+      eno = _POSIX_Keys_Set_value( key_value_pair, value );
       _POSIX_Keys_Key_value_release( executing, &lock_context );
     } else {
       _POSIX_Keys_Key_value_release( executing, &lock_context );
diff --git a/cpukit/score/include/rtems/score/rbtree.h b/cpukit/score/include/rtems/score/rbtree.h
index 2057612..1d17365 100644
--- a/cpukit/score/include/rtems/score/rbtree.h
+++ b/cpukit/score/include/rtems/score/rbtree.h
@@ -532,15 +532,19 @@ RTEMS_INLINE_ROUTINE void _RBTree_Insert_inline(
  *   node, otherwise false.
  * @param less Must return true if the specified key is less than the key of
  *   the node, otherwise false.
+ * @param adjust In case a node is found, then this function is called to get
+ *   the return value.  Usually it performs some offset operation via
+ *   RTEMS_CONTAINER_OF().
  *
- * @retval node A node with the specified key.
+ * @retval node An adjusted node with the specified key.
  * @retval NULL No node with the specified key exists in the red-black tree.
  */
-RTEMS_INLINE_ROUTINE RBTree_Node *_RBTree_Find_inline(
+RTEMS_INLINE_ROUTINE void *_RBTree_Find_inline(
   RBTree_Control *the_rbtree,
   const void     *key,
   bool         ( *equal )( const void *, const RBTree_Node * ),
-  bool         ( *less )( const void *, const RBTree_Node * )
+  bool         ( *less )( const void *, const RBTree_Node * ),
+  void        *( *adjust )( RBTree_Node * )
 )
 {
   RBTree_Node **link;
@@ -553,7 +557,7 @@ RTEMS_INLINE_ROUTINE RBTree_Node *_RBTree_Find_inline(
     parent = *link;
 
     if ( ( *equal )( key, parent ) ) {
-      return parent;
+      return ( *adjust )( parent );
     } else if ( ( *less )( key, parent ) ) {
       link = _RBTree_Left_reference( parent );
     } else {
-- 
1.8.4.5




More information about the devel mailing list