Changeset 10c4636 in rtems for cpukit/sapi


Ignore:
Timestamp:
Sep 11, 2015, 8:42:06 AM (4 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
314ff3c4
Parents:
5e4714b
git-author:
Sebastian Huber <sebastian.huber@…> (09/11/15 08:42:06)
git-committer:
Sebastian Huber <sebastian.huber@…> (09/11/15 09:28:13)
Message:

rbheap: Fix rtems_rbheap_free()

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

Close #2417.

File:
1 edited

Legend:

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

    r5e4714b r10c4636  
    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
     
    226226
    227227static void check_and_merge(
    228   rtems_chain_control *free_chain,
    229   rtems_rbtree_control *chunk_tree,
     228  rtems_rbheap_control *control,
    230229  rtems_rbheap_chunk *a,
    231   rtems_rbheap_chunk *b
    232 )
    233 {
    234   if (b != NULL_PAGE && rtems_rbheap_is_chunk_free(b)) {
    235     if (b->begin < a->begin) {
    236       rtems_rbheap_chunk *t = a;
    237 
    238       a = b;
    239       b = t;
    240     }
    241 
     230  rtems_rbheap_chunk *b,
     231  rtems_rbheap_chunk *c
     232)
     233{
     234  if (c != NULL_PAGE && rtems_rbheap_is_chunk_free(c)) {
    242235    a->size += b->size;
    243236    rtems_chain_extract_unprotected(&b->chain_node);
    244     add_to_chain(free_chain, b);
    245     rtems_rbtree_extract(chunk_tree, &b->tree_node);
     237    rtems_rbheap_add_to_spare_descriptor_chain(control, b);
     238    rtems_rbtree_extract(&control->chunk_tree, &b->tree_node);
    246239  }
    247240}
     
    252245
    253246  if (ptr != NULL) {
    254     rtems_chain_control *free_chain = &control->free_chunk_chain;
    255     rtems_rbtree_control *chunk_tree = &control->chunk_tree;
    256     rtems_rbheap_chunk *chunk = find(chunk_tree, (uintptr_t) ptr);
     247    rtems_rbheap_chunk *chunk = find(&control->chunk_tree, (uintptr_t) ptr);
    257248
    258249    if (chunk != NULL_PAGE) {
    259250      if (!rtems_rbheap_is_chunk_free(chunk)) {
    260         check_and_merge(free_chain, chunk_tree, chunk, succ(chunk));
    261         add_to_chain(free_chain, chunk);
    262         check_and_merge(free_chain, chunk_tree, chunk, pred(chunk));
     251        rtems_rbheap_chunk *other;
     252
     253        add_to_chain(&control->free_chunk_chain, chunk);
     254        other = succ(chunk);
     255        check_and_merge(control, chunk, other, other);
     256        other = pred(chunk);
     257        check_and_merge(control, other, chunk, other);
    263258      } else {
    264259        sc = RTEMS_INCORRECT_STATE;
Note: See TracChangeset for help on using the changeset viewer.