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