[rtems commit] heap: Add _Heap_Greedy_allocate_all_except_largest
Sebastian Huber
sebh at rtems.org
Tue Jun 25 15:01:50 UTC 2013
Module: rtems
Branch: master
Commit: d0d357edeb8527becced15e2784b92790d2b22c1
Changeset: http://git.rtems.org/rtems/commit/?id=d0d357edeb8527becced15e2784b92790d2b22c1
Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
Date: Tue Jun 25 12:09:50 2013 +0200
heap: Add _Heap_Greedy_allocate_all_except_largest
Add rtems_workspace_greedy_allocate_all_except_largest() and
rtems_heap_greedy_allocate_all_except_largest().
---
cpukit/libcsupport/include/rtems/malloc.h | 18 ++++++++++++++++--
cpukit/libcsupport/src/rtems_heap_greedy.c | 16 ++++++++++++++++
cpukit/rtems/include/rtems/rtems/support.h | 18 ++++++++++++++++--
cpukit/rtems/src/workspacegreedy.c | 16 ++++++++++++++++
cpukit/score/include/rtems/score/heap.h | 16 +++++++++++++++-
cpukit/score/src/heapgreedy.c | 13 +++++++++++++
6 files changed, 92 insertions(+), 5 deletions(-)
diff --git a/cpukit/libcsupport/include/rtems/malloc.h b/cpukit/libcsupport/include/rtems/malloc.h
index c428bcf..25a2e4e 100644
--- a/cpukit/libcsupport/include/rtems/malloc.h
+++ b/cpukit/libcsupport/include/rtems/malloc.h
@@ -224,7 +224,7 @@ rtems_status_code rtems_heap_extend(
/**
* @brief Greedy allocate that empties the heap.
*
- * Afterward the heap has at most @a block_count allocatable blocks of sizes
+ * Afterwards the heap has at most @a block_count allocatable blocks of sizes
* specified by @a block_sizes. The @a block_sizes must point to an array with
* @a block_count members. All other blocks are used.
*
@@ -236,10 +236,24 @@ void *rtems_heap_greedy_allocate(
);
/**
+ * @brief Greedy allocate all blocks except the largest free block.
+ *
+ * Afterwards the heap has at most one allocatable block. This block is the
+ * largest free block if it exists. The allocatable size of this block is
+ * stored in @a allocatable_size. All other blocks are used.
+ *
+ * @see rtems_heap_greedy_free().
+ */
+void *rtems_heap_greedy_allocate_all_except_largest(
+ uintptr_t *allocatable_size
+);
+
+/**
* @brief Frees space of a greedy allocation.
*
* The @a opaque argument must be the return value of
- * rtems_heap_greedy_allocate().
+ * rtems_heap_greedy_allocate() or
+ * rtems_heap_greedy_allocate_all_except_largest().
*/
void rtems_heap_greedy_free( void *opaque );
diff --git a/cpukit/libcsupport/src/rtems_heap_greedy.c b/cpukit/libcsupport/src/rtems_heap_greedy.c
index a63ff91..19ab28b 100644
--- a/cpukit/libcsupport/src/rtems_heap_greedy.c
+++ b/cpukit/libcsupport/src/rtems_heap_greedy.c
@@ -39,6 +39,22 @@ void *rtems_heap_greedy_allocate(
return opaque;
}
+void *rtems_heap_greedy_allocate_all_except_largest(
+ uintptr_t *allocatable_size
+)
+{
+ void *opaque;
+
+ _RTEMS_Lock_allocator();
+ opaque = _Heap_Greedy_allocate_all_except_largest(
+ RTEMS_Malloc_Heap,
+ allocatable_size
+ );
+ _RTEMS_Unlock_allocator();
+
+ return opaque;
+}
+
void rtems_heap_greedy_free( void *opaque )
{
_RTEMS_Lock_allocator();
diff --git a/cpukit/rtems/include/rtems/rtems/support.h b/cpukit/rtems/include/rtems/rtems/support.h
index 1f3cd3d..335b8c0 100644
--- a/cpukit/rtems/include/rtems/rtems/support.h
+++ b/cpukit/rtems/include/rtems/rtems/support.h
@@ -99,7 +99,7 @@ bool rtems_workspace_free(
/**
* @brief Greedy allocate that empties the workspace.
*
- * Afterward the heap has at most @a block_count allocateable blocks of sizes
+ * Afterwards the heap has at most @a block_count allocatable blocks of sizes
* specified by @a block_sizes. The @a block_sizes must point to an array with
* @a block_count members. All other blocks are used.
*
@@ -111,10 +111,24 @@ void *rtems_workspace_greedy_allocate(
);
/**
+ * @brief Greedy allocate all blocks except the largest free block.
+ *
+ * Afterwards the heap has at most one allocatable block. This block is the
+ * largest free block if it exists. The allocatable size of this block is
+ * stored in @a allocatable_size. All other blocks are used.
+ *
+ * @see rtems_workspace_greedy_free().
+ */
+void *rtems_workspace_greedy_allocate_all_except_largest(
+ uintptr_t *allocatable_size
+);
+
+/**
* @brief Frees space of a greedy allocation.
*
* The @a opaque argument must be the return value of
- * rtems_workspace_greedy_allocate().
+ * rtems_workspace_greedy_allocate() or
+ * rtems_workspace_greedy_allocate_all_except_largest().
*/
void rtems_workspace_greedy_free( void *opaque );
diff --git a/cpukit/rtems/src/workspacegreedy.c b/cpukit/rtems/src/workspacegreedy.c
index 8e43370..4f46e7d 100644
--- a/cpukit/rtems/src/workspacegreedy.c
+++ b/cpukit/rtems/src/workspacegreedy.c
@@ -40,6 +40,22 @@ void *rtems_workspace_greedy_allocate(
return opaque;
}
+void *rtems_workspace_greedy_allocate_all_except_largest(
+ uintptr_t *allocatable_size
+)
+{
+ void *opaque;
+
+ _Thread_Disable_dispatch();
+ opaque = _Heap_Greedy_allocate_all_except_largest(
+ &_Workspace_Area,
+ allocatable_size
+ );
+ _Thread_Enable_dispatch();
+
+ return opaque;
+}
+
void rtems_workspace_greedy_free( void *opaque )
{
_Thread_Disable_dispatch();
diff --git a/cpukit/score/include/rtems/score/heap.h b/cpukit/score/include/rtems/score/heap.h
index 2937490..bea9f3e 100644
--- a/cpukit/score/include/rtems/score/heap.h
+++ b/cpukit/score/include/rtems/score/heap.h
@@ -595,7 +595,7 @@ void _Heap_Iterate(
/**
* @brief Greedy allocate that empties the heap.
*
- * Afterward the heap has at most @a block_count allocateable blocks of sizes
+ * Afterwards the heap has at most @a block_count allocatable blocks of sizes
* specified by @a block_sizes. The @a block_sizes must point to an array with
* @a block_count members. All other blocks are used.
*
@@ -608,6 +608,20 @@ Heap_Block *_Heap_Greedy_allocate(
);
/**
+ * @brief Greedy allocate all blocks except the largest free block.
+ *
+ * Afterwards the heap has at most one allocatable block. This block is the
+ * largest free block if it exists. The allocatable size of this block is
+ * stored in @a allocatable_size. All other blocks are used.
+ *
+ * @see _Heap_Greedy_free().
+ */
+Heap_Block *_Heap_Greedy_allocate_all_except_largest(
+ Heap_Control *heap,
+ uintptr_t *allocatable_size
+);
+
+/**
* @brief Frees blocks of a greedy allocation.
*
* The @a blocks must be the return value of _Heap_Greedy_allocate().
diff --git a/cpukit/score/src/heapgreedy.c b/cpukit/score/src/heapgreedy.c
index 23eb4cd..b5c61a4 100644
--- a/cpukit/score/src/heapgreedy.c
+++ b/cpukit/score/src/heapgreedy.c
@@ -75,6 +75,19 @@ Heap_Block *_Heap_Greedy_allocate(
return blocks;
}
+Heap_Block *_Heap_Greedy_allocate_all_except_largest(
+ Heap_Control *heap,
+ uintptr_t *allocatable_size
+)
+{
+ Heap_Information info;
+
+ _Heap_Get_free_information( heap, &info );
+ *allocatable_size = info.largest - HEAP_BLOCK_HEADER_SIZE + HEAP_ALLOC_BONUS;
+
+ return _Heap_Greedy_allocate( heap, allocatable_size, 1 );
+}
+
void _Heap_Greedy_free(
Heap_Control *heap,
Heap_Block *blocks
More information about the vc
mailing list