heapmm.h revision 1b362b15af34006e6a11974088a46d42b903418e
1/* 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 12/* This code is in the public domain. 13** Version: 1.1 Author: Walt Karas 14*/ 15 16/* External header file for Heap Memory Manager. See documentation in 17** heapmm.html. 18*/ 19 20#undef HMM_PROCESS 21 22/* Include once per configuration in a particular translation unit. */ 23 24#ifndef HMM_CNFG_NUM 25 26/* Default configuration. */ 27 28#ifndef HMM_INC_CNFG_DFLT 29#define HMM_INC_CNFG_DFLT 30#define HMM_PROCESS 31#endif 32 33#elif HMM_CNFG_NUM == 0 34 35/* Test configuration. */ 36 37#ifndef HMM_INC_CNFG_0 38#define HMM_INC_CNFG_0 39#define HMM_PROCESS 40#endif 41 42#elif HMM_CNFG_NUM == 1 43 44#ifndef HMM_INC_CNFG_1 45#define HMM_INC_CNFG_1 46#define HMM_PROCESS 47#endif 48 49#elif HMM_CNFG_NUM == 2 50 51#ifndef HMM_INC_CNFG_2 52#define HMM_INC_CNFG_2 53#define HMM_PROCESS 54#endif 55 56#elif HMM_CNFG_NUM == 3 57 58#ifndef HMM_INC_CNFG_3 59#define HMM_INC_CNFG_3 60#define HMM_PROCESS 61#endif 62 63#elif HMM_CNFG_NUM == 4 64 65#ifndef HMM_INC_CNFG_4 66#define HMM_INC_CNFG_4 67#define HMM_PROCESS 68#endif 69 70#elif HMM_CNFG_NUM == 5 71 72#ifndef HMM_INC_CNFG_5 73#define HMM_INC_CNFG_5 74#define HMM_PROCESS 75#endif 76 77#endif 78 79#ifdef HMM_PROCESS 80 81#include "hmm_cnfg.h" 82 83/* Heap descriptor. */ 84typedef struct HMM_UNIQUE(structure) 85{ 86 /* private: */ 87 88 /* Pointer to (payload of) root node in AVL tree. This field should 89 ** really be the AVL tree descriptor (type avl_avl). But (in the 90 ** instantiation of the AVL tree generic package used in package) the 91 ** AVL tree descriptor simply contains a pointer to the root. So, 92 ** whenever a pointer to the AVL tree descriptor is needed, I use the 93 ** cast: 94 ** 95 ** (avl_avl *) &(heap_desc->avl_tree_root) 96 ** 97 ** (where heap_desc is a pointer to a heap descriptor). This trick 98 ** allows me to avoid including cavl_if.h in this external header. */ 99 void *avl_tree_root; 100 101 /* Pointer to first byte of last block freed, after any coalescing. */ 102 void *last_freed; 103 104 /* public: */ 105 106 HMM_UNIQUE(size_bau) num_baus_can_shrink; 107 void *end_of_shrinkable_chunk; 108} 109HMM_UNIQUE(descriptor); 110 111/* Prototypes for externally-callable functions. */ 112 113void HMM_UNIQUE(init)(HMM_UNIQUE(descriptor) *desc); 114 115void *HMM_UNIQUE(alloc)( 116 HMM_UNIQUE(descriptor) *desc, HMM_UNIQUE(size_aau) num_addr_align_units); 117 118/* NOT YET IMPLEMENTED */ 119void *HMM_UNIQUE(greedy_alloc)( 120 HMM_UNIQUE(descriptor) *desc, HMM_UNIQUE(size_aau) needed_addr_align_units, 121 HMM_UNIQUE(size_aau) coveted_addr_align_units); 122 123int HMM_UNIQUE(resize)( 124 HMM_UNIQUE(descriptor) *desc, void *mem, 125 HMM_UNIQUE(size_aau) num_addr_align_units); 126 127/* NOT YET IMPLEMENTED */ 128int HMM_UNIQUE(greedy_resize)( 129 HMM_UNIQUE(descriptor) *desc, void *mem, 130 HMM_UNIQUE(size_aau) needed_addr_align_units, 131 HMM_UNIQUE(size_aau) coveted_addr_align_units); 132 133void HMM_UNIQUE(free)(HMM_UNIQUE(descriptor) *desc, void *mem); 134 135HMM_UNIQUE(size_aau) HMM_UNIQUE(true_size)(void *mem); 136 137HMM_UNIQUE(size_aau) HMM_UNIQUE(largest_available)( 138 HMM_UNIQUE(descriptor) *desc); 139 140void HMM_UNIQUE(new_chunk)( 141 HMM_UNIQUE(descriptor) *desc, void *start_of_chunk, 142 HMM_UNIQUE(size_bau) num_block_align_units); 143 144void HMM_UNIQUE(grow_chunk)( 145 HMM_UNIQUE(descriptor) *desc, void *end_of_chunk, 146 HMM_UNIQUE(size_bau) num_block_align_units); 147 148/* NOT YET IMPLEMENTED */ 149void HMM_UNIQUE(shrink_chunk)( 150 HMM_UNIQUE(descriptor) *desc, 151 HMM_UNIQUE(size_bau) num_block_align_units); 152 153#endif /* defined HMM_PROCESS */ 154