Changeset ec978d9 in rtems


Ignore:
Timestamp:
Jun 12, 2013, 9:29:12 AM (6 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
49cdf40
Parents:
7a34ca37
git-author:
Sebastian Huber <sebastian.huber@…> (06/12/13 09:29:12)
git-committer:
Sebastian Huber <sebastian.huber@…> (06/14/13 14:26:06)
Message:

score: Add _Chain_Insert_ordered_unprotected()

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • cpukit/score/inline/rtems/score/chain.inl

    r7a34ca37 rec978d9  
    727727}
    728728
     729/**
     730 * @brief Chain node order.
     731 *
     732 * @param[in] left The left node.
     733 * @param[in] right The right node.
     734 *
     735 * @retval true According to the order the left node precedes the right node.
     736 * @retval false Otherwise.
     737 */
     738typedef bool ( *Chain_Node_order )(
     739  const Chain_Node *left,
     740  const Chain_Node *right
     741);
     742
     743/**
     744 * @brief Inserts a node into the chain according to the order relation.
     745 *
     746 * After the operation the chain contains the node to insert and the order
     747 * relation holds for all nodes from the head up to the inserted node.  Nodes
     748 * after the inserted node are not moved.
     749 *
     750 * @param[in/out] chain The chain.
     751 * @param[in/out] to_insert The node to insert.
     752 * @param[in] order The order relation.
     753 */
     754RTEMS_INLINE_ROUTINE void _Chain_Insert_ordered_unprotected(
     755  Chain_Control *chain,
     756  Chain_Node *to_insert,
     757  Chain_Node_order order
     758)
     759{
     760  const Chain_Node *tail = _Chain_Immutable_tail( chain );
     761  Chain_Node *next = _Chain_First( chain );
     762
     763  while ( next != tail && !( *order )( to_insert, next ) ) {
     764    next = _Chain_Next( next );
     765  }
     766
     767  _Chain_Insert_unprotected( _Chain_Previous( next ), to_insert );
     768}
     769
    729770/** @} */
    730771
  • testsuites/sptests/spchain/init.c

    r7a34ca37 rec978d9  
    217217    rtems_test_assert( count == i + 1 );
    218218  }
     219}
     220
     221static bool test_order( const Chain_Node *left, const Chain_Node *right )
     222{
     223  return left < right;
     224}
     225
     226static void test_chain_insert_ordered( void )
     227{
     228  Chain_Control chain = CHAIN_INITIALIZER_EMPTY(chain);
     229  Chain_Node nodes[5];
     230  const Chain_Node *tail;
     231  const Chain_Node *node;
     232  size_t n = RTEMS_ARRAY_SIZE( nodes );
     233  size_t i = 0;
     234
     235  puts( "INIT - Verify _Chain_Insert_ordered_unprotected" );
     236
     237  _Chain_Insert_ordered_unprotected( &chain, &nodes[4], test_order );
     238  _Chain_Insert_ordered_unprotected( &chain, &nodes[2], test_order );
     239  _Chain_Insert_ordered_unprotected( &chain, &nodes[0], test_order );
     240  _Chain_Insert_ordered_unprotected( &chain, &nodes[3], test_order );
     241  _Chain_Insert_ordered_unprotected( &chain, &nodes[1], test_order );
     242
     243  tail = _Chain_Immutable_tail( &chain );
     244  node = _Chain_Immutable_first( &chain );
     245  while ( node != tail && i < n ) {
     246    rtems_test_assert( node == &nodes[ i ] );
     247    ++i;
     248    node = _Chain_Immutable_next( node );
     249  }
     250
     251  rtems_test_assert( i == n );
    219252}
    220253
     
    261294  test_chain_control_initializer();
    262295  test_chain_node_count();
     296  test_chain_insert_ordered();
    263297
    264298  puts( "*** END OF RTEMS CHAIN API TEST ***" );
  • testsuites/sptests/spchain/spchain.scn

    r7a34ca37 rec978d9  
    1414INIT - Verify rtems_chain_control initializer
    1515INIT - Verify rtems_chain_node_count_unprotected
     16INIT - Verify _Chain_Insert_ordered_unprotected
    1617*** END OF RTEMS CHAIN API TEST ***
Note: See TracChangeset for help on using the changeset viewer.