diff --git a/src/core/malloc.c b/src/core/malloc.c index d694f555..32fd5fc0 100644 --- a/src/core/malloc.c +++ b/src/core/malloc.c @@ -144,6 +144,18 @@ static unsigned int discard_cache ( void ) { return discarded; } +/** + * Discard all cached data + * + */ +static void discard_all_cache ( void ) { + unsigned int discarded; + + do { + discarded = discard_cache(); + } while ( discarded ); +} + /** * Allocate a memory block * @@ -458,6 +470,19 @@ struct init_fn heap_init_fn __init_fn ( INIT_EARLY ) = { .initialise = init_heap, }; +/** + * Discard all cached data on shutdown + * + */ +static void shutdown_cache ( int booting __unused ) { + discard_all_cache(); +} + +/** Memory allocator shutdown function */ +struct startup_fn heap_startup_fn __startup_fn ( STARTUP_EARLY ) = { + .shutdown = shutdown_cache, +}; + #if 0 #include /**