From 26a73bcdec52db6920ceed92adbb555a41bfd495 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Thu, 8 Oct 2026 01:25:57 +0200 Subject: [PATCH] score: Flatten the red-black tree node The red-black tree node held its links and its color in a nested member. The nesting came from the entry macro of the header which the previous commit removed. It served no purpose, and each access had to name the nested member. Move the links and the color into the node. Change the prefix of the fields from rbe_ of the entry to rbn_ of the node. The Linux API wrapper renames the Linux fields with "#define rb_left rbn_left" and "#define rb_right rbn_right". Other Linux compatibility layers such as the linuxkpi of FreeBSD define rb_left and rb_right as object-like macros. The prefix rbn_ is no Linux name, so these macros leave the fields alone. The tests sprbtree01 and ts-unit-no-clock-0 passed on the boards of eight targets. Target Processor aarch64/zynqmp_apu Cortex-A53 LS1046A Cortex-A72 arm/zynqmp_rpu_lock_step Cortex-R5F arm/samrh71_flexram Cortex-M7 arm/xilinx_zynq_zc702 Cortex-A9 riscv/mpfs_e51 E51 riscv/mpfs_u54 U54 sparc/gr740 LEON4 Update #5804. Assisted-by: Claude:claude-opus-5-5 claude-code Signed-off-by: Sebastian Huber --- contrib/cpukit/jffs2/readinode.c | 4 +- cpukit/include/linux/rbtree.h | 4 +- cpukit/include/rtems/score/rbtree.h | 53 ++++++++++------------- cpukit/include/rtems/score/watchdogimpl.h | 10 ++--- cpukit/posix/src/mutexunlock.c | 12 ++--- cpukit/score/src/rbtreeextract.c | 2 +- 6 files changed, 38 insertions(+), 47 deletions(-) diff --git a/contrib/cpukit/jffs2/readinode.c b/contrib/cpukit/jffs2/readinode.c index c0b506e1ad..23e4212352 100644 --- a/contrib/cpukit/jffs2/readinode.c +++ b/contrib/cpukit/jffs2/readinode.c @@ -434,8 +434,8 @@ static void eat_last(struct rb_root *root, struct rb_node *node) node->rb_left->__rb_parent_color = node->__rb_parent_color; #else /* __rtems__ */ { - node->rb_left->Node.rbe_parent = node->Node.rbe_parent; - node->rb_left->Node.rbe_color = node->Node.rbe_color; + node->rb_left->rbn_parent = node->rbn_parent; + node->rb_left->rbn_color = node->rbn_color; } #endif /* __rtems__ */ } diff --git a/cpukit/include/linux/rbtree.h b/cpukit/include/linux/rbtree.h index 2b12f28753..f90a8dd2a5 100644 --- a/cpukit/include/linux/rbtree.h +++ b/cpukit/include/linux/rbtree.h @@ -45,9 +45,9 @@ extern "C" { #define rb_node RBTree_Node -#define rb_left Node.rbe_left +#define rb_left rbn_left -#define rb_right Node.rbe_right +#define rb_right rbn_right /* * Getting rid of this placeholder structure is a bit difficult. The use of diff --git a/cpukit/include/rtems/score/rbtree.h b/cpukit/include/rtems/score/rbtree.h index eb68662660..4db9caaed6 100644 --- a/cpukit/include/rtems/score/rbtree.h +++ b/cpukit/include/rtems/score/rbtree.h @@ -77,29 +77,24 @@ struct RBTree_Control; */ typedef struct RBTree_Node { /** - * @brief This member contains the links and the color of the node. + * @brief This member references the left child of the node. */ - struct { - /** - * @brief This member references the left child of the node. - */ - struct RBTree_Node *rbe_left; + struct RBTree_Node *rbn_left; - /** - * @brief This member references the right child of the node. - */ - struct RBTree_Node *rbe_right; + /** + * @brief This member references the right child of the node. + */ + struct RBTree_Node *rbn_right; - /** - * @brief This member references the parent of the node. - */ - struct RBTree_Node *rbe_parent; + /** + * @brief This member references the parent of the node. + */ + struct RBTree_Node *rbn_parent; - /** - * @brief This member contains the color of the node. - */ - int rbe_color; - } Node; + /** + * @brief This member contains the color of the node. + */ + int rbn_color; } RBTree_Node; /** @@ -145,7 +140,7 @@ typedef struct RBTree_Control { */ static inline int _RBTree_Color( const RBTree_Node *the_node ) { - return the_node->Node.rbe_color; + return the_node->rbn_color; } /** @@ -157,7 +152,7 @@ static inline int _RBTree_Color( const RBTree_Node *the_node ) */ static inline void _RBTree_Set_color( RBTree_Node *the_node, int color ) { - the_node->Node.rbe_color = color; + the_node->rbn_color = color; } /** @@ -172,7 +167,7 @@ static inline void _RBTree_Set_parent( RBTree_Node *parent ) { - the_node->Node.rbe_parent = parent; + the_node->rbn_parent = parent; } /** @@ -184,7 +179,7 @@ static inline void _RBTree_Set_parent( */ static inline void _RBTree_Set_left( RBTree_Node *the_node, RBTree_Node *left ) { - the_node->Node.rbe_left = left; + the_node->rbn_left = left; } /** @@ -199,7 +194,7 @@ static inline void _RBTree_Set_right( RBTree_Node *right ) { - the_node->Node.rbe_right = right; + the_node->rbn_right = right; } /** @@ -444,7 +439,7 @@ static inline RBTree_Node *const *_RBTree_Root_const_reference( */ static inline RBTree_Node *_RBTree_Parent( const RBTree_Node *the_node ) { - return the_node->Node.rbe_parent; + return the_node->rbn_parent; } /** @@ -458,7 +453,7 @@ static inline RBTree_Node *_RBTree_Parent( const RBTree_Node *the_node ) */ static inline RBTree_Node *_RBTree_Left( const RBTree_Node *the_node ) { - return the_node->Node.rbe_left; + return the_node->rbn_left; } /** @@ -471,7 +466,7 @@ static inline RBTree_Node *_RBTree_Left( const RBTree_Node *the_node ) */ static inline RBTree_Node **_RBTree_Left_reference( RBTree_Node *the_node ) { - return &the_node->Node.rbe_left; + return &the_node->rbn_left; } /** @@ -485,7 +480,7 @@ static inline RBTree_Node **_RBTree_Left_reference( RBTree_Node *the_node ) */ static inline RBTree_Node *_RBTree_Right( const RBTree_Node *the_node ) { - return the_node->Node.rbe_right; + return the_node->rbn_right; } /** @@ -498,7 +493,7 @@ static inline RBTree_Node *_RBTree_Right( const RBTree_Node *the_node ) */ static inline RBTree_Node **_RBTree_Right_reference( RBTree_Node *the_node ) { - return &the_node->Node.rbe_right; + return &the_node->rbn_right; } /** diff --git a/cpukit/include/rtems/score/watchdogimpl.h b/cpukit/include/rtems/score/watchdogimpl.h index d93b2b87d0..693173e188 100644 --- a/cpukit/include/rtems/score/watchdogimpl.h +++ b/cpukit/include/rtems/score/watchdogimpl.h @@ -93,14 +93,14 @@ typedef enum { * @see _Watchdog_Preinitialize(). */ #if defined( RTEMS_SMP ) - #define WATCHDOG_INITIALIZER( routine ) \ - { { { { NULL, NULL, NULL, WATCHDOG_INACTIVE } } }, \ - &_Per_CPU_Information[ 0 ].per_cpu, \ - ( routine ), \ + #define WATCHDOG_INITIALIZER( routine ) \ + { { { NULL, NULL, NULL, WATCHDOG_INACTIVE } }, \ + &_Per_CPU_Information[ 0 ].per_cpu, \ + ( routine ), \ 0 } #else #define WATCHDOG_INITIALIZER( routine ) \ - { { { { NULL, NULL, NULL, WATCHDOG_INACTIVE } } }, ( routine ), 0 } + { { { NULL, NULL, NULL, WATCHDOG_INACTIVE } }, ( routine ), 0 } #endif /** diff --git a/cpukit/posix/src/mutexunlock.c b/cpukit/posix/src/mutexunlock.c index a58b9274f4..79c90f9d55 100644 --- a/cpukit/posix/src/mutexunlock.c +++ b/cpukit/posix/src/mutexunlock.c @@ -67,14 +67,10 @@ bool _POSIX_Mutex_Auto_initialization( POSIX_Mutex_Control *the_mutex ) zero |= (unsigned long) the_mutex->Recursive.Mutex.Queue.Queue.owner; zero |= (unsigned long) the_mutex->Recursive.Mutex.Queue.Queue.name; zero |= the_mutex->Recursive.nest_level; - zero |= (unsigned long) - the_mutex->Priority_ceiling.Node.RBTree.Node.rbe_left; - zero |= (unsigned long) - the_mutex->Priority_ceiling.Node.RBTree.Node.rbe_right; - zero |= (unsigned long) - the_mutex->Priority_ceiling.Node.RBTree.Node.rbe_parent; - zero |= (unsigned long) - the_mutex->Priority_ceiling.Node.RBTree.Node.rbe_color; + zero |= (unsigned long) the_mutex->Priority_ceiling.Node.RBTree.rbn_left; + zero |= (unsigned long) the_mutex->Priority_ceiling.Node.RBTree.rbn_right; + zero |= (unsigned long) the_mutex->Priority_ceiling.Node.RBTree.rbn_parent; + zero |= (unsigned long) the_mutex->Priority_ceiling.Node.RBTree.rbn_color; zero |= (unsigned long) the_mutex->Priority_ceiling.priority; zero |= (unsigned long) ( the_mutex->Priority_ceiling.priority >> 32 ); zero |= (unsigned long) the_mutex->scheduler; diff --git a/cpukit/score/src/rbtreeextract.c b/cpukit/score/src/rbtreeextract.c index b6d6b7da42..dbbb5d3322 100644 --- a/cpukit/score/src/rbtreeextract.c +++ b/cpukit/score/src/rbtreeextract.c @@ -153,7 +153,7 @@ static void _RBTree_Remove( RBTree_Control *head, RBTree_Node *elm ) _RBTree_Set_parent( _RBTree_Left( old ), elm ); color = _RBTree_Color( elm ); - elm->Node = old->Node; + *elm = *old; } _RBTree_Swap_child( head, old, elm );