diff options
| author | Michael Brown | 2007-01-18 21:11:04 +0100 |
|---|---|---|
| committer | Michael Brown | 2007-01-18 21:11:04 +0100 |
| commit | 6d4e37cf42a16c1e0b2393efe4902a2030907dbe (patch) | |
| tree | aa880f0549e7a70ff913183099ba17db056aad47 /src/core | |
| parent | Include stdlib.h rather than malloc.h (diff) | |
| download | ipxe-6d4e37cf42a16c1e0b2393efe4902a2030907dbe.tar.gz ipxe-6d4e37cf42a16c1e0b2393efe4902a2030907dbe.tar.xz ipxe-6d4e37cf42a16c1e0b2393efe4902a2030907dbe.zip | |
Move include/malloc.h to include/gpxe/malloc.h, since everything in there
is now gPXE-specific. (The standard malloc() et al have been in stdlib.h
for a while).
Add free memory counter.
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/heap.c | 2 | ||||
| -rw-r--r-- | src/core/malloc.c | 11 |
2 files changed, 11 insertions, 2 deletions
diff --git a/src/core/heap.c b/src/core/heap.c index f2c7e80b6..4afd270b1 100644 --- a/src/core/heap.c +++ b/src/core/heap.c @@ -1,4 +1,4 @@ -#include <malloc.h> +#include <gpxe/malloc.h> #include <gpxe/heap.h> /** diff --git a/src/core/malloc.c b/src/core/malloc.c index db2b500c9..448080b4f 100644 --- a/src/core/malloc.c +++ b/src/core/malloc.c @@ -22,7 +22,7 @@ #include <strings.h> #include <io.h> #include <gpxe/list.h> -#include <malloc.h> +#include <gpxe/malloc.h> /** @file * @@ -69,6 +69,9 @@ struct autosized_block { /** List of free memory blocks */ static LIST_HEAD ( free_blocks ); +/** Total amount of free memory */ +size_t freemem; + /** * Allocate a memory block * @@ -134,6 +137,9 @@ void * alloc_memblock ( size_t size, size_t align ) { */ if ( pre_size < MIN_MEMBLOCK_SIZE ) list_del ( &pre->list ); + /* Update total free memory */ + freemem -= size; + /* Return allocated block */ DBG ( "Allocated [%p,%p)\n", block, ( ( ( void * ) block ) + size ) ); return block; @@ -206,6 +212,9 @@ void free_memblock ( void *ptr, size_t size ) { freeing->size += block->size; list_del ( &block->list ); } + + /* Update free memory counter */ + freemem += size; } /** |
