2018-04-20 11:12:33 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014-2018 Freie Universität Berlin
|
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @ingroup pkg_tlsf_malloc
|
|
|
|
* @ingroup pkg
|
|
|
|
* @ingroup sys
|
|
|
|
* @{
|
|
|
|
* @file
|
|
|
|
*
|
|
|
|
* @brief TLSF-based global memory allocator.
|
|
|
|
* @author Juan I Carrano
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "tlsf.h"
|
|
|
|
#include "tlsf-malloc.h"
|
2019-08-19 16:31:06 +02:00
|
|
|
#include "tlsf-malloc-internal.h"
|
2018-04-20 11:12:33 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Global memory heap (really a collection of pools, or areas)
|
|
|
|
**/
|
2019-08-19 16:31:06 +02:00
|
|
|
tlsf_t tlsf_malloc_gheap = NULL;
|
2018-04-20 11:12:33 +02:00
|
|
|
|
|
|
|
int tlsf_add_global_pool(void *mem, size_t bytes)
|
|
|
|
{
|
2019-08-19 16:31:06 +02:00
|
|
|
if (tlsf_malloc_gheap == NULL) {
|
|
|
|
tlsf_malloc_gheap = tlsf_create_with_pool(mem, bytes);
|
|
|
|
return tlsf_malloc_gheap == NULL;
|
2018-04-20 11:12:33 +02:00
|
|
|
}
|
|
|
|
else {
|
2019-08-19 16:31:06 +02:00
|
|
|
return tlsf_add_pool(tlsf_malloc_gheap, mem, bytes) == NULL;
|
2018-04-20 11:12:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-16 19:17:32 +02:00
|
|
|
tlsf_t _tlsf_get_global_control(void)
|
2018-04-20 11:12:33 +02:00
|
|
|
{
|
2019-08-19 16:31:06 +02:00
|
|
|
return tlsf_malloc_gheap;
|
2018-04-20 11:12:33 +02:00
|
|
|
}
|
|
|
|
|
2018-06-11 17:09:54 +02:00
|
|
|
void tlsf_size_walker(void* ptr, size_t size, int used, void* user)
|
|
|
|
{
|
|
|
|
printf("\t%p %s size: %u (%p)\n", ptr, used ? "used" : "free", (unsigned int)size, ptr);
|
|
|
|
|
|
|
|
if (used) {
|
|
|
|
((tlsf_size_container_t *)user)->used += (unsigned int)size;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
((tlsf_size_container_t *)user)->free += (unsigned int)size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-20 11:12:33 +02:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|