Ignore:
Timestamp:
10/09/21 14:12:07 (10 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
9be97a3
Parents:
3f0ad2b
git-author:
Sebastian Huber <sebastian.huber@…> (10/09/21 14:12:07)
git-committer:
Sebastian Huber <sebastian.huber@…> (10/25/21 06:01:02)
Message:

score: Simplify _Watchdog_Next_first()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpukit/include/rtems/score/watchdogimpl.h

    r3f0ad2b ra4112bd  
    352352
    353353/**
    354  * @brief Sets the first node of the header.
    355  *
    356  * Sets the first node of the header to either the leftmost child node of the
    357  *  watchdog control node, or if not present sets it to the right child node of
    358  * the watchdog control node. if both are not present, the new first node is
    359  * the parent node of the current first node.
    360  *
    361  * @param[in, out] header The watchdog header.
    362  * @param the_watchdog The watchdog control node for the operation.
     354 * @brief Sets the first watchdog of the watchdog collection to the next
     355 * watchdog of the current first watchdog.
     356 *
     357 * This function may be used during watchdog removals, see _Watchdog_Remove()
     358 * and _Watchdog_Tickle().
     359 *
     360 * @param[in, out] header is the watchdog collection header.
     361 *
     362 * @param first is the current first watchdog which should be removed
     363 *   afterwards.
    363364 */
    364365RTEMS_INLINE_ROUTINE void _Watchdog_Next_first(
    365   Watchdog_Header  *header,
    366   Watchdog_Control *the_watchdog
    367 )
    368 {
    369   RBTree_Node *node = _RBTree_Right( &the_watchdog->Node.RBTree );
    370 
    371   if ( node != NULL ) {
    372     RBTree_Node *left;
    373 
    374     while ( ( left = _RBTree_Left( node ) ) != NULL ) {
    375       node = left;
    376     }
    377 
    378     header->first = node;
     366  Watchdog_Header        *header,
     367  const Watchdog_Control *first
     368)
     369{
     370  RBTree_Node *right;
     371
     372  /*
     373   * This function uses the following properties of red-black trees:
     374   *
     375   * 1. Every leaf (NULL) is black.
     376   *
     377   * 2. If a node is red, then both its children are black.
     378   *
     379   * 3. Every simple path from a node to a descendant leaf contains the same
     380   *    number of black nodes.
     381   *
     382   * The first node has no left child.  So every path from the first node has
     383   * exactly one black node (including leafs).  The first node cannot have a
     384   * non-leaf black right child.  It may have a red right child.  In this case
     385   * both children must be leafs.
     386   */
     387  _Assert( header->first == &first->Node.RBTree );
     388  _Assert( _RBTree_Left( &first->Node.RBTree ) == NULL );
     389  right = _RBTree_Right( &first->Node.RBTree );
     390
     391  if ( right != NULL ) {
     392    _Assert( RB_COLOR( right, Node ) == RB_RED );
     393    _Assert( _RBTree_Left( right ) == NULL );
     394    _Assert( _RBTree_Right( right ) == NULL );
     395    header->first = right;
    379396  } else {
    380     header->first = _RBTree_Parent( &the_watchdog->Node.RBTree );
     397    header->first = _RBTree_Parent( &first->Node.RBTree );
    381398  }
    382399}
Note: See TracChangeset for help on using the changeset viewer.