1 #include "../../lv_conf_internal.h" 2 #if LV_USE_STDLIB_MALLOC == LV_STDLIB_BUILTIN 3 4 #ifndef LV_TLSF_H 5 #define LV_TLSF_H 6 7 /* 8 ** Two Level Segregated Fit memory allocator, version 3.1. 9 ** Written by Matthew Conte 10 ** http://tlsf.baisoku.org 11 ** 12 ** Based on the original documentation by Miguel Masmano: 13 ** http://www.gii.upv.es/tlsf/main/docs 14 ** 15 ** This implementation was written to the specification 16 ** of the document, therefore no GPL restrictions apply. 17 ** 18 ** Copyright (c) 2006-2016, Matthew Conte 19 ** All rights reserved. 20 ** 21 ** Redistribution and use in source and binary forms, with or without 22 ** modification, are permitted provided that the following conditions are met: 23 ** * Redistributions of source code must retain the above copyright 24 ** notice, this list of conditions and the following disclaimer. 25 ** * Redistributions in binary form must reproduce the above copyright 26 ** notice, this list of conditions and the following disclaimer in the 27 ** documentation and/or other materials provided with the distribution. 28 ** * Neither the name of the copyright holder nor the 29 ** names of its contributors may be used to endorse or promote products 30 ** derived from this software without specific prior written permission. 31 ** 32 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 33 ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 34 ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 35 ** DISCLAIMED. IN NO EVENT SHALL MATTHEW CONTE BE LIABLE FOR ANY 36 ** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 37 ** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 38 ** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 39 ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 40 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 41 ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 42 */ 43 44 #include "../../misc/lv_ll.h" 45 #include "../../misc/lv_types.h" 46 47 #if defined(__cplusplus) 48 extern "C" { 49 #endif 50 51 /* lv_tlsf_t: a TLSF structure. Can contain 1 to N pools. */ 52 /* lv_pool_t: a block of memory that TLSF can manage. */ 53 typedef void * lv_tlsf_t; 54 typedef void * lv_pool_t; 55 56 /* Create/destroy a memory pool. */ 57 lv_tlsf_t lv_tlsf_create(void * mem); 58 lv_tlsf_t lv_tlsf_create_with_pool(void * mem, size_t bytes); 59 void lv_tlsf_destroy(lv_tlsf_t tlsf); 60 lv_pool_t lv_tlsf_get_pool(lv_tlsf_t tlsf); 61 62 /* Add/remove memory pools. */ 63 lv_pool_t lv_tlsf_add_pool(lv_tlsf_t tlsf, void * mem, size_t bytes); 64 void lv_tlsf_remove_pool(lv_tlsf_t tlsf, lv_pool_t pool); 65 66 /* malloc/memalign/realloc/free replacements. */ 67 void * lv_tlsf_malloc(lv_tlsf_t tlsf, size_t bytes); 68 void * lv_tlsf_memalign(lv_tlsf_t tlsf, size_t align, size_t bytes); 69 void * lv_tlsf_realloc(lv_tlsf_t tlsf, void * ptr, size_t size); 70 size_t lv_tlsf_free(lv_tlsf_t tlsf, const void * ptr); 71 72 /* Returns internal block size, not original request size */ 73 size_t lv_tlsf_block_size(void * ptr); 74 75 /* Overheads/limits of internal structures. */ 76 size_t lv_tlsf_size(void); 77 size_t lv_tlsf_align_size(void); 78 size_t lv_tlsf_block_size_min(void); 79 size_t lv_tlsf_block_size_max(void); 80 size_t lv_tlsf_pool_overhead(void); 81 size_t lv_tlsf_alloc_overhead(void); 82 83 /* Debugging. */ 84 typedef void (*lv_tlsf_walker)(void * ptr, size_t size, int used, void * user); 85 void lv_tlsf_walk_pool(lv_pool_t pool, lv_tlsf_walker walker, void * user); 86 /* Returns nonzero if any internal consistency check fails. */ 87 int lv_tlsf_check(lv_tlsf_t tlsf); 88 int lv_tlsf_check_pool(lv_pool_t pool); 89 90 #if defined(__cplusplus) 91 }; 92 #endif 93 94 #endif /*LV_TLSF_H*/ 95 96 #endif /*LV_STDLIB_BUILTIN*/ 97