[rtems commit] rbheap: Fix rtems_rbheap_free()
Sebastian Huber
sebh at rtems.org
Fri Sep 11 09:28:32 UTC 2015
Module: rtems
Branch: master
Commit: 10c4636947f13f89dcabfb0c7f0f4f4966d7c7fb
Changeset: http://git.rtems.org/rtems/commit/?id=10c4636947f13f89dcabfb0c7f0f4f4966d7c7fb
Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
Date: Fri Sep 11 10:42:06 2015 +0200
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.
---
cpukit/sapi/src/rbheap.c | 37 ++++++++++++++++---------------------
testsuites/libtests/rbheap01/init.c | 5 +++++
2 files changed, 21 insertions(+), 21 deletions(-)
diff --git a/cpukit/sapi/src/rbheap.c b/cpukit/sapi/src/rbheap.c
index 6ad451c..6fc2aef 100644
--- a/cpukit/sapi/src/rbheap.c
+++ b/cpukit/sapi/src/rbheap.c
@@ -7,10 +7,10 @@
*/
/*
- * Copyright (c) 2012 embedded brains GmbH. All rights reserved.
+ * Copyright (c) 2012-2015 embedded brains GmbH. All rights reserved.
*
* embedded brains GmbH
- * Obere Lagerstr. 30
+ * Dornierstr. 4
* 82178 Puchheim
* Germany
* <rtems at embedded-brains.de>
@@ -225,24 +225,17 @@ static rtems_rbheap_chunk *succ(const rtems_rbheap_chunk *chunk)
}
static void check_and_merge(
- rtems_chain_control *free_chain,
- rtems_rbtree_control *chunk_tree,
+ rtems_rbheap_control *control,
rtems_rbheap_chunk *a,
- rtems_rbheap_chunk *b
+ rtems_rbheap_chunk *b,
+ rtems_rbheap_chunk *c
)
{
- if (b != NULL_PAGE && rtems_rbheap_is_chunk_free(b)) {
- if (b->begin < a->begin) {
- rtems_rbheap_chunk *t = a;
-
- a = b;
- b = t;
- }
-
+ if (c != NULL_PAGE && rtems_rbheap_is_chunk_free(c)) {
a->size += b->size;
rtems_chain_extract_unprotected(&b->chain_node);
- add_to_chain(free_chain, b);
- rtems_rbtree_extract(chunk_tree, &b->tree_node);
+ rtems_rbheap_add_to_spare_descriptor_chain(control, b);
+ rtems_rbtree_extract(&control->chunk_tree, &b->tree_node);
}
}
@@ -251,15 +244,17 @@ rtems_status_code rtems_rbheap_free(rtems_rbheap_control *control, void *ptr)
rtems_status_code sc = RTEMS_SUCCESSFUL;
if (ptr != NULL) {
- rtems_chain_control *free_chain = &control->free_chunk_chain;
- rtems_rbtree_control *chunk_tree = &control->chunk_tree;
- rtems_rbheap_chunk *chunk = find(chunk_tree, (uintptr_t) ptr);
+ rtems_rbheap_chunk *chunk = find(&control->chunk_tree, (uintptr_t) ptr);
if (chunk != NULL_PAGE) {
if (!rtems_rbheap_is_chunk_free(chunk)) {
- check_and_merge(free_chain, chunk_tree, chunk, succ(chunk));
- add_to_chain(free_chain, chunk);
- check_and_merge(free_chain, chunk_tree, chunk, pred(chunk));
+ rtems_rbheap_chunk *other;
+
+ add_to_chain(&control->free_chunk_chain, chunk);
+ other = succ(chunk);
+ check_and_merge(control, chunk, other, other);
+ other = pred(chunk);
+ check_and_merge(control, other, chunk, other);
} else {
sc = RTEMS_INCORRECT_STATE;
}
diff --git a/testsuites/libtests/rbheap01/init.c b/testsuites/libtests/rbheap01/init.c
index 8388e97..bc16d0a 100644
--- a/testsuites/libtests/rbheap01/init.c
+++ b/testsuites/libtests/rbheap01/init.c
@@ -170,6 +170,11 @@ static void test_chunk_tree(
.chunk_end = chunk_begin + chunk_count
};
+ rtems_test_assert(
+ rtems_chain_node_count_unprotected(&control->spare_descriptor_chain)
+ == PAGE_COUNT - chunk_count
+ );
+
_RBTree_Iterate(
&control->chunk_tree,
chunk_visitor,
More information about the vc
mailing list