Changeset edf7732 in rtems


Ignore:
Timestamp:
Sep 11, 2015, 8:42:06 AM (4 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11
Children:
9c96ea7
Parents:
deb3f29
git-author:
Sebastian Huber <sebastian.huber@…> (09/11/15 08:42:06)
git-committer:
Sebastian Huber <sebastian.huber@…> (09/11/15 09:31:27)
Message:

rbheap: Fix rtems_rbheap_free()

Remove unused descriptor of merged free chunks from the free chain and
add them to the spare descriptors.

Update #2417.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpukit/sapi/src/rbheap.c

    rdeb3f29 redf7732  
    88
    99/*
    10  * Copyright (c) 2012 embedded brains GmbH.  All rights reserved.
     10 * Copyright (c) 2012-2015 embedded brains GmbH.  All rights reserved.
    1111 *
    1212 *  embedded brains GmbH
    13  *  Obere Lagerstr. 30
     13 *  Dornierstr. 4
    1414 *  82178 Puchheim
    1515 *  Germany
     
    222222
    223223static void check_and_merge(
    224   rtems_chain_control *free_chain,
    225   rtems_rbtree_control *chunk_tree,
     224  rtems_rbheap_control *control,
    226225  rtems_rbheap_chunk *a,
    227   rtems_rbheap_chunk *b
    228 )
    229 {
    230   if (b != NULL_PAGE && rtems_rbheap_is_chunk_free(b)) {
    231     if (b->begin < a->begin) {
    232       rtems_rbheap_chunk *t = a;
    233 
    234       a = b;
    235       b = t;
    236     }
    237 
     226  rtems_rbheap_chunk *b,
     227  rtems_rbheap_chunk *c
     228)
     229{
     230  if (c != NULL_PAGE && rtems_rbheap_is_chunk_free(c)) {
    238231    a->size += b->size;
    239232    rtems_chain_extract_unprotected(&b->chain_node);
    240     add_to_chain(free_chain, b);
    241     rtems_rbtree_extract(chunk_tree, &b->tree_node);
     233    rtems_rbheap_add_to_spare_descriptor_chain(control, b);
     234    rtems_rbtree_extract(&control->chunk_tree, &b->tree_node);
    242235  }
    243236}
     
    248241
    249242  if (ptr != NULL) {
    250     rtems_chain_control *free_chain = &control->free_chunk_chain;
    251     rtems_rbtree_control *chunk_tree = &control->chunk_tree;
    252     rtems_rbheap_chunk *chunk = find(chunk_tree, (uintptr_t) ptr);
     243    rtems_rbheap_chunk *chunk = find(&control->chunk_tree, (uintptr_t) ptr);
    253244
    254245    if (chunk != NULL_PAGE) {
    255246      if (!rtems_rbheap_is_chunk_free(chunk)) {
    256         rtems_rbheap_chunk *pred = get_next(chunk, RBT_LEFT);
    257         rtems_rbheap_chunk *succ = get_next(chunk, RBT_RIGHT);
    258 
    259         check_and_merge(free_chain, chunk_tree, chunk, succ);
    260         add_to_chain(free_chain, chunk);
    261         check_and_merge(free_chain, chunk_tree, chunk, pred);
     247        rtems_rbheap_chunk *other;
     248
     249        add_to_chain(&control->free_chunk_chain, chunk);
     250        other = get_next(chunk, RBT_RIGHT);
     251        check_and_merge(control, chunk, other, other);
     252        other = get_next(chunk, RBT_LEFT);
     253        check_and_merge(control, other, chunk, other);
    262254      } else {
    263255        sc = RTEMS_INCORRECT_STATE;
  • testsuites/libtests/rbheap01/init.c

    rdeb3f29 redf7732  
    171171    .chunk_end = chunk_begin + chunk_count
    172172  };
     173
     174  rtems_test_assert(
     175    rtems_chain_node_count_unprotected(&control->spare_descriptor_chain)
     176      == PAGE_COUNT - chunk_count
     177  );
    173178
    174179  _RBTree_Iterate(
Note: See TracChangeset for help on using the changeset viewer.