diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2020-07-27 21:58:46 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2020-07-27 21:58:46 +0200 |
commit | 989d3ebf78ad149ee4e9930d7b73ac7370373a28 (patch) | |
tree | 95e8131e70480eaf2a5020f48f37499eff86b9ba /include | |
parent | ae9f7b02996d1d6d3649a69d5b3c61b259c0e465 (diff) | |
parent | 78adca381e9564a2437aefba7b3c4ac398328fea (diff) | |
download | barebox-989d3ebf78ad149ee4e9930d7b73ac7370373a28.tar.gz barebox-989d3ebf78ad149ee4e9930d7b73ac7370373a28.tar.xz |
Merge branch 'for-next/tlsf'
Diffstat (limited to 'include')
-rw-r--r-- | include/tlsf.h | 86 |
1 files changed, 65 insertions, 21 deletions
diff --git a/include/tlsf.h b/include/tlsf.h index 1917fa111b..7015de0eb5 100644 --- a/include/tlsf.h +++ b/include/tlsf.h @@ -2,46 +2,90 @@ #define INCLUDED_tlsf /* -** Two Level Segregated Fit memory allocator, version 1.9. -** Written by Matthew Conte, and placed in the Public Domain. +** Two Level Segregated Fit memory allocator, version 3.1. +** Written by Matthew Conte ** http://tlsf.baisoku.org ** ** Based on the original documentation by Miguel Masmano: -** http://rtportal.upv.es/rtmalloc/allocators/tlsf/index.shtml -** -** Please see the accompanying Readme.txt for implementation -** notes and caveats. +** http://www.gii.upv.es/tlsf/main/docs ** ** This implementation was written to the specification ** of the document, therefore no GPL restrictions apply. +** +** Copyright (c) 2006-2016, Matthew Conte +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** * Neither the name of the copyright holder nor the +** names of its contributors may be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +** DISCLAIMED. IN NO EVENT SHALL MATTHEW CONTE BE LIABLE FOR ANY +** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if defined(__cplusplus) extern "C" { #endif +#define tlsf_assert(expr) do { \ + if (unlikely(!(expr))) { \ + printf(#expr "%s %d\n", __FILE__, __LINE__); \ + } \ +} while (0) + +/* tlsf_t: a TLSF structure. Can contain 1 to N pools. */ +/* pool_t: a block of memory that TLSF can manage. */ +typedef void* tlsf_t; +typedef void* pool_t; + /* Create/destroy a memory pool. */ -typedef void* tlsf_pool; -tlsf_pool tlsf_create(void* mem, size_t bytes); -void tlsf_destroy(tlsf_pool pool); +tlsf_t tlsf_create(void* mem); +tlsf_t tlsf_create_with_pool(void* mem, size_t bytes); +void tlsf_destroy(tlsf_t tlsf); +pool_t tlsf_get_pool(tlsf_t tlsf); -/* malloc/memalign/realloc/free replacements. */ -void* tlsf_malloc(tlsf_pool pool, size_t bytes); -void* tlsf_memalign(tlsf_pool pool, size_t align, size_t bytes); -void* tlsf_realloc(tlsf_pool pool, void* ptr, size_t size); -void tlsf_free(tlsf_pool pool, void* ptr); +/* Add/remove memory pools. */ +pool_t tlsf_add_pool(tlsf_t tlsf, void* mem, size_t bytes); +void tlsf_remove_pool(tlsf_t tlsf, pool_t pool); -/* Debugging. */ -typedef void (*tlsf_walker)(void* ptr, size_t size, int used, void* user); -void tlsf_walk_heap(tlsf_pool pool, tlsf_walker walker, void* user); -/* Returns nonzero if heap check fails. */ -int tlsf_check_heap(tlsf_pool pool); +/* malloc/memalign/realloc/free replacements. */ +void* tlsf_malloc(tlsf_t tlsf, size_t bytes); +void* tlsf_memalign(tlsf_t tlsf, size_t align, size_t bytes); +void* tlsf_realloc(tlsf_t tlsf, void* ptr, size_t size); +void tlsf_free(tlsf_t tlsf, void* ptr); /* Returns internal block size, not original request size */ size_t tlsf_block_size(void* ptr); -/* Overhead of per-pool internal structures. */ -size_t tlsf_overhead(void); +/* Overheads/limits of internal structures. */ +size_t tlsf_size(void); +size_t tlsf_align_size(void); +size_t tlsf_block_size_min(void); +size_t tlsf_block_size_max(void); +size_t tlsf_pool_overhead(void); +size_t tlsf_alloc_overhead(void); + +/* Debugging. */ +typedef void (*tlsf_walker)(void* ptr, size_t size, int used, void* user); +void tlsf_walk_pool(pool_t pool, tlsf_walker walker, void* user); +/* Returns nonzero if any internal consistency check fails. */ +int tlsf_check(tlsf_t tlsf); +int tlsf_check_pool(pool_t pool); #if defined(__cplusplus) }; |