vpx_mem: remove memory manager code
vestigial. the code is stale and couldn't be configured directly; there are better ways to achieve this now Change-Id: I5a9c62e099215588cd0d7e5ae002dfc77c21a895
This commit is contained in:
parent
305492c375
commit
e5eda53e3d
1
configure
vendored
1
configure
vendored
@ -296,7 +296,6 @@ CONFIG_LIST="
|
||||
codec_srcs
|
||||
debug_libs
|
||||
fast_unaligned
|
||||
mem_manager
|
||||
mem_tracker
|
||||
mem_checks
|
||||
|
||||
|
@ -13,15 +13,6 @@
|
||||
#define VPX_MEM_INCLUDE_VPX_MEM_INTRNL_H_
|
||||
#include "./vpx_config.h"
|
||||
|
||||
#ifndef CONFIG_MEM_MANAGER
|
||||
# if defined(VXWORKS)
|
||||
# define CONFIG_MEM_MANAGER 1 /*include heap manager functionality,*/
|
||||
/*default: enabled on vxworks*/
|
||||
# else
|
||||
# define CONFIG_MEM_MANAGER 0 /*include heap manager functionality*/
|
||||
# endif
|
||||
#endif /*CONFIG_MEM_MANAGER*/
|
||||
|
||||
#ifndef CONFIG_MEM_TRACKER
|
||||
# define CONFIG_MEM_TRACKER 1 /*include xvpx_* calls in the lib*/
|
||||
#endif
|
||||
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2010 The WebM project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
|
||||
/* This code is in the public domain.
|
||||
** Version: 1.1 Author: Walt Karas
|
||||
*/
|
||||
|
||||
#include "hmm_intrnl.h"
|
||||
|
||||
void *U(alloc)(U(descriptor) *desc, U(size_aau) n) {
|
||||
#ifdef HMM_AUDIT_FAIL
|
||||
|
||||
if (desc->avl_tree_root)
|
||||
AUDIT_BLOCK(PTR_REC_TO_HEAD(desc->avl_tree_root))
|
||||
#endif
|
||||
|
||||
if (desc->last_freed) {
|
||||
#ifdef HMM_AUDIT_FAIL
|
||||
AUDIT_BLOCK(desc->last_freed)
|
||||
#endif
|
||||
|
||||
U(into_free_collection)(desc, (head_record *)(desc->last_freed));
|
||||
|
||||
desc->last_freed = 0;
|
||||
}
|
||||
|
||||
/* Add space for block header. */
|
||||
n += HEAD_AAUS;
|
||||
|
||||
/* Convert n from number of address alignment units to block alignment
|
||||
** units. */
|
||||
n = DIV_ROUND_UP(n, HMM_BLOCK_ALIGN_UNIT);
|
||||
|
||||
if (n < MIN_BLOCK_BAUS)
|
||||
n = MIN_BLOCK_BAUS;
|
||||
|
||||
{
|
||||
/* Search for the first node of the bin containing the smallest
|
||||
** block big enough to satisfy request. */
|
||||
ptr_record *ptr_rec_ptr =
|
||||
U(avl_search)(
|
||||
(U(avl_avl) *) & (desc->avl_tree_root), (U(size_bau)) n,
|
||||
AVL_GREATER_EQUAL);
|
||||
|
||||
/* If an approprate bin is found, satisfy the allocation request,
|
||||
** otherwise return null pointer. */
|
||||
return(ptr_rec_ptr ?
|
||||
U(alloc_from_bin)(desc, ptr_rec_ptr, (U(size_bau)) n) : 0);
|
||||
}
|
||||
}
|
@ -1,405 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2010 The WebM project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
|
||||
/* This code is in the public domain.
|
||||
** Version: 1.1 Author: Walt Karas
|
||||
*/
|
||||
|
||||
#include "hmm_intrnl.h"
|
||||
|
||||
void U(init)(U(descriptor) *desc) {
|
||||
desc->avl_tree_root = 0;
|
||||
desc->last_freed = 0;
|
||||
}
|
||||
|
||||
/* Remove a free block from a bin's doubly-linked list when it is not,
|
||||
** the first block in the bin.
|
||||
*/
|
||||
void U(dll_remove)(
|
||||
/* Pointer to pointer record in the block to be removed. */
|
||||
ptr_record *to_remove) {
|
||||
to_remove->prev->next = to_remove->next;
|
||||
|
||||
if (to_remove->next)
|
||||
to_remove->next->prev = to_remove->prev;
|
||||
}
|
||||
|
||||
/* Put a block into the free collection of a heap.
|
||||
*/
|
||||
void U(into_free_collection)(
|
||||
/* Pointer to heap descriptor. */
|
||||
U(descriptor) *desc,
|
||||
/* Pointer to head record of block. */
|
||||
head_record *head_ptr) {
|
||||
ptr_record *ptr_rec_ptr = HEAD_TO_PTR_REC(head_ptr);
|
||||
|
||||
ptr_record *bin_front_ptr =
|
||||
U(avl_insert)((U(avl_avl) *) & (desc->avl_tree_root), ptr_rec_ptr);
|
||||
|
||||
if (bin_front_ptr != ptr_rec_ptr) {
|
||||
/* The block was not inserted into the AVL tree because there is
|
||||
** already a bin for the size of the block. */
|
||||
|
||||
MARK_SUCCESSIVE_BLOCK_IN_FREE_BIN(head_ptr)
|
||||
ptr_rec_ptr->self = ptr_rec_ptr;
|
||||
|
||||
/* Make the block the new second block in the bin's doubly-linked
|
||||
** list. */
|
||||
ptr_rec_ptr->prev = bin_front_ptr;
|
||||
ptr_rec_ptr->next = bin_front_ptr->next;
|
||||
bin_front_ptr->next = ptr_rec_ptr;
|
||||
|
||||
if (ptr_rec_ptr->next)
|
||||
ptr_rec_ptr->next->prev = ptr_rec_ptr;
|
||||
} else
|
||||
/* Block is first block in new bin. */
|
||||
ptr_rec_ptr->next = 0;
|
||||
}
|
||||
|
||||
/* Allocate a block from a given bin. Returns a pointer to the payload
|
||||
** of the removed block. The "last freed" pointer must be null prior
|
||||
** to calling this function.
|
||||
*/
|
||||
void *U(alloc_from_bin)(
|
||||
/* Pointer to heap descriptor. */
|
||||
U(descriptor) *desc,
|
||||
/* Pointer to pointer record of first block in bin. */
|
||||
ptr_record *bin_front_ptr,
|
||||
/* Number of BAUs needed in the allocated block. If the block taken
|
||||
** from the bin is significantly larger than the number of BAUs needed,
|
||||
** the "extra" BAUs are split off to form a new free block. */
|
||||
U(size_bau) n_baus) {
|
||||
head_record *head_ptr;
|
||||
U(size_bau) rem_baus;
|
||||
|
||||
if (bin_front_ptr->next) {
|
||||
/* There are multiple blocks in this bin. Use the 2nd block in
|
||||
** the bin to avoid needless change to the AVL tree.
|
||||
*/
|
||||
|
||||
ptr_record *ptr_rec_ptr = bin_front_ptr->next;
|
||||
head_ptr = PTR_REC_TO_HEAD(ptr_rec_ptr);
|
||||
|
||||
#ifdef AUDIT_FAIL
|
||||
AUDIT_BLOCK(head_ptr)
|
||||
#endif
|
||||
|
||||
U(dll_remove)(ptr_rec_ptr);
|
||||
} else {
|
||||
/* There is only one block in the bin, so it has to be removed
|
||||
** from the AVL tree.
|
||||
*/
|
||||
|
||||
head_ptr = PTR_REC_TO_HEAD(bin_front_ptr);
|
||||
|
||||
U(avl_remove)(
|
||||
(U(avl_avl) *) & (desc->avl_tree_root), BLOCK_BAUS(head_ptr));
|
||||
}
|
||||
|
||||
MARK_BLOCK_ALLOCATED(head_ptr)
|
||||
|
||||
rem_baus = BLOCK_BAUS(head_ptr) - n_baus;
|
||||
|
||||
if (rem_baus >= MIN_BLOCK_BAUS) {
|
||||
/* Since there are enough "extra" BAUs, split them off to form
|
||||
** a new free block.
|
||||
*/
|
||||
|
||||
head_record *rem_head_ptr =
|
||||
(head_record *) BAUS_FORWARD(head_ptr, n_baus);
|
||||
|
||||
/* Change the next block's header to reflect the fact that the
|
||||
** block preceeding it is now smaller.
|
||||
*/
|
||||
SET_PREV_BLOCK_BAUS(
|
||||
BAUS_FORWARD(head_ptr, head_ptr->block_size), rem_baus)
|
||||
|
||||
head_ptr->block_size = n_baus;
|
||||
|
||||
rem_head_ptr->previous_block_size = n_baus;
|
||||
rem_head_ptr->block_size = rem_baus;
|
||||
|
||||
desc->last_freed = rem_head_ptr;
|
||||
}
|
||||
|
||||
return(HEAD_TO_PTR_REC(head_ptr));
|
||||
}
|
||||
|
||||
/* Take a block out of the free collection.
|
||||
*/
|
||||
void U(out_of_free_collection)(
|
||||
/* Descriptor of heap that block is in. */
|
||||
U(descriptor) *desc,
|
||||
/* Pointer to head of block to take out of free collection. */
|
||||
head_record *head_ptr) {
|
||||
ptr_record *ptr_rec_ptr = HEAD_TO_PTR_REC(head_ptr);
|
||||
|
||||
if (ptr_rec_ptr->self == ptr_rec_ptr)
|
||||
/* Block is not the front block in its bin, so all we have to
|
||||
** do is take it out of the bin's doubly-linked list. */
|
||||
U(dll_remove)(ptr_rec_ptr);
|
||||
else {
|
||||
ptr_record *next = ptr_rec_ptr->next;
|
||||
|
||||
if (next)
|
||||
/* Block is the front block in its bin, and there is at least
|
||||
** one other block in the bin. Substitute the next block for
|
||||
** the front block. */
|
||||
U(avl_subst)((U(avl_avl) *) & (desc->avl_tree_root), next);
|
||||
else
|
||||
/* Block is the front block in its bin, but there is no other
|
||||
** block in the bin. Eliminate the bin. */
|
||||
U(avl_remove)(
|
||||
(U(avl_avl) *) & (desc->avl_tree_root), BLOCK_BAUS(head_ptr));
|
||||
}
|
||||
}
|
||||
|
||||
void U(free)(U(descriptor) *desc, void *payload_ptr) {
|
||||
/* Flags if coalesce with adjacent block. */
|
||||
int coalesce;
|
||||
|
||||
head_record *fwd_head_ptr;
|
||||
head_record *free_head_ptr = PTR_REC_TO_HEAD(payload_ptr);
|
||||
|
||||
desc->num_baus_can_shrink = 0;
|
||||
|
||||
#ifdef HMM_AUDIT_FAIL
|
||||
|
||||
AUDIT_BLOCK(free_head_ptr)
|
||||
|
||||
/* Make sure not freeing an already free block. */
|
||||
if (!IS_BLOCK_ALLOCATED(free_head_ptr))
|
||||
HMM_AUDIT_FAIL
|
||||
|
||||
if (desc->avl_tree_root)
|
||||
/* Audit root block in AVL tree. */
|
||||
AUDIT_BLOCK(PTR_REC_TO_HEAD(desc->avl_tree_root))
|
||||
|
||||
#endif
|
||||
|
||||
fwd_head_ptr =
|
||||
(head_record *) BAUS_FORWARD(free_head_ptr, free_head_ptr->block_size);
|
||||
|
||||
if (free_head_ptr->previous_block_size) {
|
||||
/* Coalesce with backward block if possible. */
|
||||
|
||||
head_record *bkwd_head_ptr =
|
||||
(head_record *) BAUS_BACKWARD(
|
||||
free_head_ptr, free_head_ptr->previous_block_size);
|
||||
|
||||
#ifdef HMM_AUDIT_FAIL
|
||||
AUDIT_BLOCK(bkwd_head_ptr)
|
||||
#endif
|
||||
|
||||
if (bkwd_head_ptr == (head_record *)(desc->last_freed)) {
|
||||
desc->last_freed = 0;
|
||||
coalesce = 1;
|
||||
} else if (IS_BLOCK_ALLOCATED(bkwd_head_ptr))
|
||||
coalesce = 0;
|
||||
else {
|
||||
U(out_of_free_collection)(desc, bkwd_head_ptr);
|
||||
coalesce = 1;
|
||||
}
|
||||
|
||||
if (coalesce) {
|
||||
bkwd_head_ptr->block_size += free_head_ptr->block_size;
|
||||
SET_PREV_BLOCK_BAUS(fwd_head_ptr, BLOCK_BAUS(bkwd_head_ptr))
|
||||
free_head_ptr = bkwd_head_ptr;
|
||||
}
|
||||
}
|
||||
|
||||
if (fwd_head_ptr->block_size == 0) {
|
||||
/* Block to be freed is last block before dummy end-of-chunk block. */
|
||||
desc->end_of_shrinkable_chunk =
|
||||
BAUS_FORWARD(fwd_head_ptr, DUMMY_END_BLOCK_BAUS);
|
||||
desc->num_baus_can_shrink = BLOCK_BAUS(free_head_ptr);
|
||||
|
||||
if (PREV_BLOCK_BAUS(free_head_ptr) == 0)
|
||||
/* Free block is the entire chunk, so shrinking can eliminate
|
||||
** entire chunk including dummy end block. */
|
||||
desc->num_baus_can_shrink += DUMMY_END_BLOCK_BAUS;
|
||||
} else {
|
||||
/* Coalesce with forward block if possible. */
|
||||
|
||||
#ifdef HMM_AUDIT_FAIL
|
||||
AUDIT_BLOCK(fwd_head_ptr)
|
||||
#endif
|
||||
|
||||
if (fwd_head_ptr == (head_record *)(desc->last_freed)) {
|
||||
desc->last_freed = 0;
|
||||
coalesce = 1;
|
||||
} else if (IS_BLOCK_ALLOCATED(fwd_head_ptr))
|
||||
coalesce = 0;
|
||||
else {
|
||||
U(out_of_free_collection)(desc, fwd_head_ptr);
|
||||
coalesce = 1;
|
||||
}
|
||||
|
||||
if (coalesce) {
|
||||
free_head_ptr->block_size += fwd_head_ptr->block_size;
|
||||
|
||||
fwd_head_ptr =
|
||||
(head_record *) BAUS_FORWARD(
|
||||
fwd_head_ptr, BLOCK_BAUS(fwd_head_ptr));
|
||||
|
||||
SET_PREV_BLOCK_BAUS(fwd_head_ptr, BLOCK_BAUS(free_head_ptr))
|
||||
|
||||
if (fwd_head_ptr->block_size == 0) {
|
||||
/* Coalesced block to be freed is last block before dummy
|
||||
** end-of-chunk block. */
|
||||
desc->end_of_shrinkable_chunk =
|
||||
BAUS_FORWARD(fwd_head_ptr, DUMMY_END_BLOCK_BAUS);
|
||||
desc->num_baus_can_shrink = BLOCK_BAUS(free_head_ptr);
|
||||
|
||||
if (PREV_BLOCK_BAUS(free_head_ptr) == 0)
|
||||
/* Free block is the entire chunk, so shrinking can
|
||||
** eliminate entire chunk including dummy end block. */
|
||||
desc->num_baus_can_shrink += DUMMY_END_BLOCK_BAUS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (desc->last_freed) {
|
||||
/* There is a last freed block, but it is not adjacent to the
|
||||
** block being freed by this call to free, so put the last
|
||||
** freed block into the free collection.
|
||||
*/
|
||||
|
||||
#ifdef HMM_AUDIT_FAIL
|
||||
AUDIT_BLOCK(desc->last_freed)
|
||||
#endif
|
||||
|
||||
U(into_free_collection)(desc, (head_record *)(desc->last_freed));
|
||||
}
|
||||
|
||||
desc->last_freed = free_head_ptr;
|
||||
}
|
||||
|
||||
void U(new_chunk)(U(descriptor) *desc, void *start, U(size_bau) n_baus) {
|
||||
#ifdef HMM_AUDIT_FAIL
|
||||
|
||||
if (desc->avl_tree_root)
|
||||
/* Audit root block in AVL tree. */
|
||||
AUDIT_BLOCK(PTR_REC_TO_HEAD(desc->avl_tree_root))
|
||||
#endif
|
||||
|
||||
#undef HEAD_PTR
|
||||
#define HEAD_PTR ((head_record *) start)
|
||||
|
||||
/* Make the chunk one big free block followed by a dummy end block.
|
||||
*/
|
||||
|
||||
n_baus -= DUMMY_END_BLOCK_BAUS;
|
||||
|
||||
HEAD_PTR->previous_block_size = 0;
|
||||
HEAD_PTR->block_size = n_baus;
|
||||
|
||||
U(into_free_collection)(desc, HEAD_PTR);
|
||||
|
||||
/* Set up the dummy end block. */
|
||||
start = BAUS_FORWARD(start, n_baus);
|
||||
HEAD_PTR->previous_block_size = n_baus;
|
||||
HEAD_PTR->block_size = 0;
|
||||
|
||||
#undef HEAD_PTR
|
||||
}
|
||||
|
||||
#ifdef HMM_AUDIT_FAIL
|
||||
|
||||
/* Function that does audit fail actions defined my preprocessor symbol,
|
||||
** and returns a dummy integer value.
|
||||
*/
|
||||
int U(audit_block_fail_dummy_return)(void) {
|
||||
HMM_AUDIT_FAIL
|
||||
|
||||
/* Dummy return. */
|
||||
return(0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* AVL Tree instantiation. */
|
||||
|
||||
#ifdef HMM_AUDIT_FAIL
|
||||
|
||||
/* The AVL tree generic package passes an ACCESS of 1 when it "touches"
|
||||
** a child node for the first time during a particular operation. I use
|
||||
** this feature to audit only one time (per operation) the free blocks
|
||||
** that are tree nodes. Since the root node is not a child node, it has
|
||||
** to be audited directly.
|
||||
*/
|
||||
|
||||
/* The pain you feel while reading these macros will not be in vain. It
|
||||
** will remove all doubt from you mind that C++ inline functions are
|
||||
** a very good thing.
|
||||
*/
|
||||
|
||||
#define AVL_GET_LESS(H, ACCESS) \
|
||||
(((ACCESS) ? AUDIT_BLOCK_AS_EXPR(PTR_REC_TO_HEAD(H)) : 0), (H)->self)
|
||||
#define AVL_GET_GREATER(H, ACCESS) \
|
||||
(((ACCESS) ? AUDIT_BLOCK_AS_EXPR(PTR_REC_TO_HEAD(H)) : 0), (H)->prev)
|
||||
|
||||
#else
|
||||
|
||||
#define AVL_GET_LESS(H, ACCESS) ((H)->self)
|
||||
#define AVL_GET_GREATER(H, ACCESS) ((H)->prev)
|
||||
|
||||
#endif
|
||||
|
||||
#define AVL_SET_LESS(H, LH) (H)->self = (LH);
|
||||
#define AVL_SET_GREATER(H, GH) (H)->prev = (GH);
|
||||
|
||||
/* high bit of high bit of
|
||||
** block_size previous_block_size balance factor
|
||||
** ----------- ------------------- --------------
|
||||
** 0 0 n/a (block allocated)
|
||||
** 0 1 1
|
||||
** 1 0 -1
|
||||
** 1 1 0
|
||||
*/
|
||||
|
||||
#define AVL_GET_BALANCE_FACTOR(H) \
|
||||
((((head_record *) (PTR_REC_TO_HEAD(H)))->block_size & \
|
||||
HIGH_BIT_BAU_SIZE) ? \
|
||||
(((head_record *) (PTR_REC_TO_HEAD(H)))->previous_block_size & \
|
||||
HIGH_BIT_BAU_SIZE ? 0 : -1) : 1)
|
||||
|
||||
#define AVL_SET_BALANCE_FACTOR(H, BF) \
|
||||
{ \
|
||||
register head_record *p = \
|
||||
(head_record *) PTR_REC_TO_HEAD(H); \
|
||||
register int bal_f = (BF); \
|
||||
\
|
||||
if (bal_f <= 0) \
|
||||
p->block_size |= HIGH_BIT_BAU_SIZE; \
|
||||
else \
|
||||
p->block_size &= ~HIGH_BIT_BAU_SIZE; \
|
||||
if (bal_f >= 0) \
|
||||
p->previous_block_size |= HIGH_BIT_BAU_SIZE; \
|
||||
else \
|
||||
p->previous_block_size &= ~HIGH_BIT_BAU_SIZE; \
|
||||
}
|
||||
|
||||
#define COMPARE_KEY_KEY(K1, K2) ((K1) == (K2) ? 0 : ((K1) > (K2) ? 1 : -1))
|
||||
|
||||
#define AVL_COMPARE_KEY_NODE(K, H) \
|
||||
COMPARE_KEY_KEY(K, BLOCK_BAUS(PTR_REC_TO_HEAD(H)))
|
||||
|
||||
#define AVL_COMPARE_NODE_NODE(H1, H2) \
|
||||
COMPARE_KEY_KEY(BLOCK_BAUS(PTR_REC_TO_HEAD(H1)), \
|
||||
BLOCK_BAUS(PTR_REC_TO_HEAD(H2)))
|
||||
|
||||
#define AVL_NULL ((ptr_record *) 0)
|
||||
|
||||
#define AVL_IMPL_MASK \
|
||||
( AVL_IMPL_INSERT | AVL_IMPL_SEARCH | AVL_IMPL_REMOVE | AVL_IMPL_SUBST )
|
||||
|
||||
#include "cavl_impl.h"
|
@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2010 The WebM project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
|
||||
/* This code is in the public domain.
|
||||
** Version: 1.1 Author: Walt Karas
|
||||
*/
|
||||
|
||||
/* The function in this file performs default actions if self-auditing
|
||||
** finds heap corruption. Don't rely on this code to handle the
|
||||
** case where HMM is being used to implement the malloc and free standard
|
||||
** library functions. Rewrite the function if necessary to avoid using
|
||||
** I/O and execution termination functions that call malloc or free.
|
||||
** In Unix, for example, you would replace the fputs calls with calls
|
||||
** to the write system call using file handle number 2.
|
||||
*/
|
||||
#include "hmm_intrnl.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static int entered = 0;
|
||||
|
||||
/* Print abort message, file and line. Terminate execution.
|
||||
*/
|
||||
void hmm_dflt_abort(const char *file, const char *line) {
|
||||
/* Avoid use of printf(), which is more likely to use heap. */
|
||||
|
||||
if (entered)
|
||||
|
||||
/* The standard I/O functions called a heap function and caused
|
||||
** an indirect recursive call to this function. So we'll have
|
||||
** to just exit without printing a message. */
|
||||
while (1);
|
||||
|
||||
entered = 1;
|
||||
|
||||
fputs("\n_abort - Heap corruption\n" "File: ", stderr);
|
||||
fputs(file, stderr);
|
||||
fputs(" Line: ", stderr);
|
||||
fputs(line, stderr);
|
||||
fputs("\n\n", stderr);
|
||||
fputs("hmm_dflt_abort: while(1)!!!\n", stderr);
|
||||
fflush(stderr);
|
||||
|
||||
while (1);
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2010 The WebM project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
|
||||
/* This code is in the public domain.
|
||||
** Version: 1.1 Author: Walt Karas
|
||||
*/
|
||||
|
||||
#include "hmm_intrnl.h"
|
||||
|
||||
void U(grow_chunk)(U(descriptor) *desc, void *end, U(size_bau) n_baus) {
|
||||
#undef HEAD_PTR
|
||||
#define HEAD_PTR ((head_record *) end)
|
||||
|
||||
end = BAUS_BACKWARD(end, DUMMY_END_BLOCK_BAUS);
|
||||
|
||||
#ifdef HMM_AUDIT_FAIL
|
||||
|
||||
if (HEAD_PTR->block_size != 0)
|
||||
/* Chunk does not have valid dummy end block. */
|
||||
HMM_AUDIT_FAIL
|
||||
|
||||
#endif
|
||||
|
||||
/* Create a new block that absorbs the old dummy end block. */
|
||||
HEAD_PTR->block_size = n_baus;
|
||||
|
||||
/* Set up the new dummy end block. */
|
||||
{
|
||||
head_record *dummy = (head_record *) BAUS_FORWARD(end, n_baus);
|
||||
dummy->previous_block_size = n_baus;
|
||||
dummy->block_size = 0;
|
||||
}
|
||||
|
||||
/* Simply free the new block, allowing it to coalesce with any
|
||||
** free block at that was the last block in the chunk prior to
|
||||
** growth.
|
||||
*/
|
||||
U(free)(desc, HEAD_TO_PTR_REC(end));
|
||||
|
||||
#undef HEAD_PTR
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2010 The WebM project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
|
||||
/* This code is in the public domain.
|
||||
** Version: 1.1 Author: Walt Karas
|
||||
*/
|
||||
|
||||
#include "hmm_intrnl.h"
|
||||
|
||||
U(size_aau) U(largest_available)(U(descriptor) *desc) {
|
||||
U(size_bau) largest;
|
||||
|
||||
if (!(desc->avl_tree_root))
|
||||
largest = 0;
|
||||
else {
|
||||
#ifdef HMM_AUDIT_FAIL
|
||||
/* Audit root block in AVL tree. */
|
||||
AUDIT_BLOCK(PTR_REC_TO_HEAD(desc->avl_tree_root))
|
||||
#endif
|
||||
|
||||
largest =
|
||||
BLOCK_BAUS(
|
||||
PTR_REC_TO_HEAD(
|
||||
U(avl_search)(
|
||||
(U(avl_avl) *) & (desc->avl_tree_root),
|
||||
(U(size_bau)) ~(U(size_bau)) 0, AVL_LESS)));
|
||||
}
|
||||
|
||||
if (desc->last_freed) {
|
||||
/* Size of last freed block. */
|
||||
register U(size_bau) lf_size;
|
||||
|
||||
#ifdef HMM_AUDIT_FAIL
|
||||
AUDIT_BLOCK(desc->last_freed)
|
||||
#endif
|
||||
|
||||
lf_size = BLOCK_BAUS(desc->last_freed);
|
||||
|
||||
if (lf_size > largest)
|
||||
largest = lf_size;
|
||||
}
|
||||
|
||||
/* Convert largest size to AAUs and subract head size leaving payload
|
||||
** size.
|
||||
*/
|
||||
return(largest ?
|
||||
((largest * ((U(size_aau)) HMM_BLOCK_ALIGN_UNIT)) - HEAD_AAUS) :
|
||||
0);
|
||||
}
|
@ -1,114 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2010 The WebM project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
|
||||
/* This code is in the public domain.
|
||||
** Version: 1.1 Author: Walt Karas
|
||||
*/
|
||||
|
||||
#include "hmm_intrnl.h"
|
||||
|
||||
int U(resize)(U(descriptor) *desc, void *mem, U(size_aau) n) {
|
||||
U(size_aau) i;
|
||||
head_record *next_head_ptr;
|
||||
head_record *head_ptr = PTR_REC_TO_HEAD(mem);
|
||||
|
||||
/* Flag. */
|
||||
int next_block_free;
|
||||
|
||||
/* Convert n from desired block size in AAUs to BAUs. */
|
||||
n += HEAD_AAUS;
|
||||
n = DIV_ROUND_UP(n, HMM_BLOCK_ALIGN_UNIT);
|
||||
|
||||
if (n < MIN_BLOCK_BAUS)
|
||||
n = MIN_BLOCK_BAUS;
|
||||
|
||||
#ifdef HMM_AUDIT_FAIL
|
||||
|
||||
AUDIT_BLOCK(head_ptr)
|
||||
|
||||
if (!IS_BLOCK_ALLOCATED(head_ptr))
|
||||
HMM_AUDIT_FAIL
|
||||
|
||||
if (desc->avl_tree_root)
|
||||
AUDIT_BLOCK(PTR_REC_TO_HEAD(desc->avl_tree_root))
|
||||
|
||||
#endif
|
||||
|
||||
i = head_ptr->block_size;
|
||||
|
||||
next_head_ptr =
|
||||
(head_record *) BAUS_FORWARD(head_ptr, head_ptr->block_size);
|
||||
|
||||
next_block_free =
|
||||
(next_head_ptr == desc->last_freed) ||
|
||||
!IS_BLOCK_ALLOCATED(next_head_ptr);
|
||||
|
||||
if (next_block_free)
|
||||
/* Block can expand into next free block. */
|
||||
i += BLOCK_BAUS(next_head_ptr);
|
||||
|
||||
if (n > i)
|
||||
/* Not enough room for block to expand. */
|
||||
return(-1);
|
||||
|
||||
if (next_block_free) {
|
||||
#ifdef HMM_AUDIT_FAIL
|
||||
AUDIT_BLOCK(next_head_ptr)
|
||||
#endif
|
||||
|
||||
if (next_head_ptr == desc->last_freed)
|
||||
desc->last_freed = 0;
|
||||
else
|
||||
U(out_of_free_collection)(desc, next_head_ptr);
|
||||
|
||||
next_head_ptr =
|
||||
(head_record *) BAUS_FORWARD(head_ptr, (U(size_bau)) i);
|
||||
}
|
||||
|
||||
/* Set i to number of "extra" BAUs. */
|
||||
i -= n;
|
||||
|
||||
if (i < MIN_BLOCK_BAUS)
|
||||
/* Not enough extra BAUs to be a block on their own, so just keep them
|
||||
** in the block being resized.
|
||||
*/
|
||||
{
|
||||
n += i;
|
||||
i = n;
|
||||
} else {
|
||||
/* There are enough "leftover" BAUs in the next block to
|
||||
** form a remainder block. */
|
||||
|
||||
head_record *rem_head_ptr;
|
||||
|
||||
rem_head_ptr = (head_record *) BAUS_FORWARD(head_ptr, n);
|
||||
|
||||
rem_head_ptr->previous_block_size = (U(size_bau)) n;
|
||||
rem_head_ptr->block_size = (U(size_bau)) i;
|
||||
|
||||
if (desc->last_freed) {
|
||||
#ifdef HMM_AUDIT_FAIL
|
||||
AUDIT_BLOCK(desc->last_freed)
|
||||
#endif
|
||||
|
||||
U(into_free_collection)(desc, (head_record *)(desc->last_freed));
|
||||
|
||||
desc->last_freed = 0;
|
||||
}
|
||||
|
||||
desc->last_freed = rem_head_ptr;
|
||||
}
|
||||
|
||||
head_ptr->block_size = (U(size_bau)) n;
|
||||
next_head_ptr->previous_block_size = (U(size_bau)) i;
|
||||
|
||||
return(0);
|
||||
}
|
@ -1,103 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2010 The WebM project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
|
||||
/* This code is in the public domain.
|
||||
** Version: 1.1 Author: Walt Karas
|
||||
*/
|
||||
|
||||
#include "hmm_intrnl.h"
|
||||
|
||||
void U(shrink_chunk)(U(descriptor) *desc, U(size_bau) n_baus_to_shrink) {
|
||||
head_record *dummy_end_block = (head_record *)
|
||||
BAUS_BACKWARD(desc->end_of_shrinkable_chunk, DUMMY_END_BLOCK_BAUS);
|
||||
|
||||
#ifdef HMM_AUDIT_FAIL
|
||||
|
||||
if (dummy_end_block->block_size != 0)
|
||||
/* Chunk does not have valid dummy end block. */
|
||||
HMM_AUDIT_FAIL
|
||||
|
||||
#endif
|
||||
|
||||
if (n_baus_to_shrink) {
|
||||
head_record *last_block = (head_record *)
|
||||
BAUS_BACKWARD(
|
||||
dummy_end_block, dummy_end_block->previous_block_size);
|
||||
|
||||
#ifdef HMM_AUDIT_FAIL
|
||||
AUDIT_BLOCK(last_block)
|
||||
#endif
|
||||
|
||||
if (last_block == desc->last_freed) {
|
||||
U(size_bau) bs = BLOCK_BAUS(last_block);
|
||||
|
||||
/* Chunk will not be shrunk out of existence if
|
||||
** 1. There is at least one allocated block in the chunk
|
||||
** and the amount to shrink is exactly the size of the
|
||||
** last block, OR
|
||||
** 2. After the last block is shrunk, there will be enough
|
||||
** BAUs left in it to form a minimal size block. */
|
||||
int chunk_will_survive =
|
||||
(PREV_BLOCK_BAUS(last_block) && (n_baus_to_shrink == bs)) ||
|
||||
(n_baus_to_shrink <= (U(size_bau))(bs - MIN_BLOCK_BAUS));
|
||||
|
||||
if (chunk_will_survive ||
|
||||
(!PREV_BLOCK_BAUS(last_block) &&
|
||||
(n_baus_to_shrink ==
|
||||
(U(size_bau))(bs + DUMMY_END_BLOCK_BAUS)))) {
|
||||
desc->last_freed = 0;
|
||||
|
||||
if (chunk_will_survive) {
|
||||
bs -= n_baus_to_shrink;
|
||||
|
||||
if (bs) {
|
||||
/* The last (non-dummy) block was not completely
|
||||
** eliminated by the shrink. */
|
||||
|
||||
last_block->block_size = bs;
|
||||
|
||||
/* Create new dummy end record.
|
||||
*/
|
||||
dummy_end_block =
|
||||
(head_record *) BAUS_FORWARD(last_block, bs);
|
||||
dummy_end_block->previous_block_size = bs;
|
||||
dummy_end_block->block_size = 0;
|
||||
|
||||
#ifdef HMM_AUDIT_FAIL
|
||||
|
||||
if (desc->avl_tree_root)
|
||||
AUDIT_BLOCK(PTR_REC_TO_HEAD(desc->avl_tree_root))
|
||||
#endif
|
||||
|
||||
U(into_free_collection)(desc, last_block);
|
||||
} else {
|
||||
/* The last (non-dummy) block was completely
|
||||
** eliminated by the shrink. Make its head
|
||||
** the new dummy end block.
|
||||
*/
|
||||
last_block->block_size = 0;
|
||||
last_block->previous_block_size &= ~HIGH_BIT_BAU_SIZE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HMM_AUDIT_FAIL
|
||||
else
|
||||
HMM_AUDIT_FAIL
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef HMM_AUDIT_FAIL
|
||||
else
|
||||
HMM_AUDIT_FAIL
|
||||
#endif
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2010 The WebM project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
|
||||
/* This code is in the public domain.
|
||||
** Version: 1.1 Author: Walt Karas
|
||||
*/
|
||||
|
||||
#include "hmm_intrnl.h"
|
||||
|
||||
U(size_aau) U(true_size)(void *payload_ptr) {
|
||||
register head_record *head_ptr = PTR_REC_TO_HEAD(payload_ptr);
|
||||
|
||||
#ifdef HMM_AUDIT_FAIL
|
||||
AUDIT_BLOCK(head_ptr)
|
||||
#endif
|
||||
|
||||
/* Convert block size from BAUs to AAUs. Subtract head size, leaving
|
||||
** payload size.
|
||||
*/
|
||||
return(
|
||||
(BLOCK_BAUS(head_ptr) * ((U(size_aau)) HMM_BLOCK_ALIGN_UNIT)) -
|
||||
HEAD_AAUS);
|
||||
}
|
@ -1,228 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2010 The WebM project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#ifndef VPX_MEM_MEMORY_MANAGER_INCLUDE_CAVL_IF_H_
|
||||
#define VPX_MEM_MEMORY_MANAGER_INCLUDE_CAVL_IF_H_
|
||||
|
||||
/* Abstract AVL Tree Generic C Package.
|
||||
** Interface generation header file.
|
||||
**
|
||||
** This code is in the public domain. See cavl_tree.html for interface
|
||||
** documentation.
|
||||
**
|
||||
** Version: 1.5 Author: Walt Karas
|
||||
*/
|
||||
|
||||
/* This header contains the definition of CHAR_BIT (number of bits in a
|
||||
** char). */
|
||||
#include <limits.h>
|
||||
|
||||
#undef L_
|
||||
#undef L_EST_LONG_BIT
|
||||
#undef L_SIZE
|
||||
#undef L_SC
|
||||
#undef L_LONG_BIT
|
||||
#undef L_BIT_ARR_DEFN
|
||||
|
||||
#ifndef AVL_SEARCH_TYPE_DEFINED_
|
||||
#define AVL_SEARCH_TYPE_DEFINED_
|
||||
|
||||
typedef enum {
|
||||
AVL_EQUAL = 1,
|
||||
AVL_LESS = 2,
|
||||
AVL_GREATER = 4,
|
||||
AVL_LESS_EQUAL = AVL_EQUAL | AVL_LESS,
|
||||
AVL_GREATER_EQUAL = AVL_EQUAL | AVL_GREATER
|
||||
}
|
||||
avl_search_type;
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef AVL_UNIQUE
|
||||
|
||||
#define L_ AVL_UNIQUE
|
||||
|
||||
#else
|
||||
|
||||
#define L_(X) X
|
||||
|
||||
#endif
|
||||
|
||||
/* Determine storage class for function prototypes. */
|
||||
#ifdef AVL_PRIVATE
|
||||
|
||||
#define L_SC static
|
||||
|
||||
#else
|
||||
|
||||
#define L_SC extern
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef AVL_SIZE
|
||||
|
||||
#define L_SIZE AVL_SIZE
|
||||
|
||||
#else
|
||||
|
||||
#define L_SIZE unsigned long
|
||||
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
#ifdef AVL_INSIDE_STRUCT
|
||||
|
||||
AVL_INSIDE_STRUCT
|
||||
|
||||
#endif
|
||||
|
||||
AVL_HANDLE root;
|
||||
}
|
||||
L_(avl);
|
||||
|
||||
/* Function prototypes. */
|
||||
|
||||
L_SC void L_(init)(L_(avl) *tree);
|
||||
|
||||
L_SC int L_(is_empty)(L_(avl) *tree);
|
||||
|
||||
L_SC AVL_HANDLE L_(insert)(L_(avl) *tree, AVL_HANDLE h);
|
||||
|
||||
L_SC AVL_HANDLE L_(search)(L_(avl) *tree, AVL_KEY k, avl_search_type st);
|
||||
|
||||
L_SC AVL_HANDLE L_(search_least)(L_(avl) *tree);
|
||||
|
||||
L_SC AVL_HANDLE L_(search_greatest)(L_(avl) *tree);
|
||||
|
||||
L_SC AVL_HANDLE L_(remove)(L_(avl) *tree, AVL_KEY k);
|
||||
|
||||
L_SC AVL_HANDLE L_(subst)(L_(avl) *tree, AVL_HANDLE new_node);
|
||||
|
||||
#ifdef AVL_BUILD_ITER_TYPE
|
||||
|
||||
L_SC int L_(build)(
|
||||
L_(avl) *tree, AVL_BUILD_ITER_TYPE p, L_SIZE num_nodes);
|
||||
|
||||
#endif
|
||||
|
||||
/* ANSI C/ISO C++ require that a long have at least 32 bits. Set
|
||||
** L_EST_LONG_BIT to be the greatest multiple of 8 in the range
|
||||
** 32 - 64 (inclusive) that is less than or equal to the number of
|
||||
** bits in a long.
|
||||
*/
|
||||
|
||||
#if (((LONG_MAX >> 31) >> 7) == 0)
|
||||
|
||||
#define L_EST_LONG_BIT 32
|
||||
|
||||
#elif (((LONG_MAX >> 31) >> 15) == 0)
|
||||
|
||||
#define L_EST_LONG_BIT 40
|
||||
|
||||
#elif (((LONG_MAX >> 31) >> 23) == 0)
|
||||
|
||||
#define L_EST_LONG_BIT 48
|
||||
|
||||
#elif (((LONG_MAX >> 31) >> 31) == 0)
|
||||
|
||||
#define L_EST_LONG_BIT 56
|
||||
|
||||
#else
|
||||
|
||||
#define L_EST_LONG_BIT 64
|
||||
|
||||
#endif
|
||||
|
||||
/* Number of bits in a long. */
|
||||
#define L_LONG_BIT (sizeof(long) * CHAR_BIT)
|
||||
|
||||
/* The macro L_BIT_ARR_DEFN defines a bit array whose index is a (0-based)
|
||||
** node depth. The definition depends on whether the maximum depth is more
|
||||
** or less than the number of bits in a single long.
|
||||
*/
|
||||
|
||||
#if ((AVL_MAX_DEPTH) > L_EST_LONG_BIT)
|
||||
|
||||
/* Maximum depth may be more than number of bits in a long. */
|
||||
|
||||
#define L_BIT_ARR_DEFN(NAME) \
|
||||
unsigned long NAME[((AVL_MAX_DEPTH) + L_LONG_BIT - 1) / L_LONG_BIT];
|
||||
|
||||
#else
|
||||
|
||||
/* Maximum depth is definitely less than number of bits in a long. */
|
||||
|
||||
#define L_BIT_ARR_DEFN(NAME) unsigned long NAME;
|
||||
|
||||
#endif
|
||||
|
||||
/* Iterator structure. */
|
||||
typedef struct {
|
||||
/* Tree being iterated over. */
|
||||
L_(avl) *tree_;
|
||||
|
||||
/* Records a path into the tree. If bit n is true, indicates
|
||||
** take greater branch from the nth node in the path, otherwise
|
||||
** take the less branch. bit 0 gives branch from root, and
|
||||
** so on. */
|
||||
L_BIT_ARR_DEFN(branch)
|
||||
|
||||
/* Zero-based depth of path into tree. */
|
||||
unsigned depth;
|
||||
|
||||
/* Handles of nodes in path from root to current node (returned by *). */
|
||||
AVL_HANDLE path_h[(AVL_MAX_DEPTH) - 1];
|
||||
}
|
||||
L_(iter);
|
||||
|
||||
/* Iterator function prototypes. */
|
||||
|
||||
L_SC void L_(start_iter)(
|
||||
L_(avl) *tree, L_(iter) *iter, AVL_KEY k, avl_search_type st);
|
||||
|
||||
L_SC void L_(start_iter_least)(L_(avl) *tree, L_(iter) *iter);
|
||||
|
||||
L_SC void L_(start_iter_greatest)(L_(avl) *tree, L_(iter) *iter);
|
||||
|
||||
L_SC AVL_HANDLE L_(get_iter)(L_(iter) *iter);
|
||||
|
||||
L_SC void L_(incr_iter)(L_(iter) *iter);
|
||||
|
||||
L_SC void L_(decr_iter)(L_(iter) *iter);
|
||||
|
||||
L_SC void L_(init_iter)(L_(iter) *iter);
|
||||
|
||||
#define AVL_IMPL_INIT 1
|
||||
#define AVL_IMPL_IS_EMPTY (1 << 1)
|
||||
#define AVL_IMPL_INSERT (1 << 2)
|
||||
#define AVL_IMPL_SEARCH (1 << 3)
|
||||
#define AVL_IMPL_SEARCH_LEAST (1 << 4)
|
||||
#define AVL_IMPL_SEARCH_GREATEST (1 << 5)
|
||||
#define AVL_IMPL_REMOVE (1 << 6)
|
||||
#define AVL_IMPL_BUILD (1 << 7)
|
||||
#define AVL_IMPL_START_ITER (1 << 8)
|
||||
#define AVL_IMPL_START_ITER_LEAST (1 << 9)
|
||||
#define AVL_IMPL_START_ITER_GREATEST (1 << 10)
|
||||
#define AVL_IMPL_GET_ITER (1 << 11)
|
||||
#define AVL_IMPL_INCR_ITER (1 << 12)
|
||||
#define AVL_IMPL_DECR_ITER (1 << 13)
|
||||
#define AVL_IMPL_INIT_ITER (1 << 14)
|
||||
#define AVL_IMPL_SUBST (1 << 15)
|
||||
|
||||
#define AVL_IMPL_ALL (~0)
|
||||
|
||||
#undef L_
|
||||
#undef L_EST_LONG_BIT
|
||||
#undef L_SIZE
|
||||
#undef L_SC
|
||||
#undef L_LONG_BIT
|
||||
#undef L_BIT_ARR_DEFN
|
||||
|
||||
#endif // VPX_MEM_MEMORY_MANAGER_INCLUDE_CAVL_IF_H_
|
File diff suppressed because it is too large
Load Diff
@ -1,155 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2010 The WebM project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#ifndef VPX_MEM_MEMORY_MANAGER_INCLUDE_HEAPMM_H_
|
||||
#define VPX_MEM_MEMORY_MANAGER_INCLUDE_HEAPMM_H_
|
||||
|
||||
/* This code is in the public domain.
|
||||
** Version: 1.1 Author: Walt Karas
|
||||
*/
|
||||
|
||||
/* External header file for Heap Memory Manager. See documentation in
|
||||
** heapmm.html.
|
||||
*/
|
||||
|
||||
#undef HMM_PROCESS
|
||||
|
||||
/* Include once per configuration in a particular translation unit. */
|
||||
|
||||
#ifndef HMM_CNFG_NUM
|
||||
|
||||
/* Default configuration. */
|
||||
|
||||
#ifndef HMM_INC_CNFG_DFLT
|
||||
#define HMM_INC_CNFG_DFLT
|
||||
#define HMM_PROCESS
|
||||
#endif
|
||||
|
||||
#elif HMM_CNFG_NUM == 0
|
||||
|
||||
/* Test configuration. */
|
||||
|
||||
#ifndef HMM_INC_CNFG_0
|
||||
#define HMM_INC_CNFG_0
|
||||
#define HMM_PROCESS
|
||||
#endif
|
||||
|
||||
#elif HMM_CNFG_NUM == 1
|
||||
|
||||
#ifndef HMM_INC_CNFG_1
|
||||
#define HMM_INC_CNFG_1
|
||||
#define HMM_PROCESS
|
||||
#endif
|
||||
|
||||
#elif HMM_CNFG_NUM == 2
|
||||
|
||||
#ifndef HMM_INC_CNFG_2
|
||||
#define HMM_INC_CNFG_2
|
||||
#define HMM_PROCESS
|
||||
#endif
|
||||
|
||||
#elif HMM_CNFG_NUM == 3
|
||||
|
||||
#ifndef HMM_INC_CNFG_3
|
||||
#define HMM_INC_CNFG_3
|
||||
#define HMM_PROCESS
|
||||
#endif
|
||||
|
||||
#elif HMM_CNFG_NUM == 4
|
||||
|
||||
#ifndef HMM_INC_CNFG_4
|
||||
#define HMM_INC_CNFG_4
|
||||
#define HMM_PROCESS
|
||||
#endif
|
||||
|
||||
#elif HMM_CNFG_NUM == 5
|
||||
|
||||
#ifndef HMM_INC_CNFG_5
|
||||
#define HMM_INC_CNFG_5
|
||||
#define HMM_PROCESS
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef HMM_PROCESS
|
||||
|
||||
#include "hmm_cnfg.h"
|
||||
|
||||
/* Heap descriptor. */
|
||||
typedef struct HMM_UNIQUE(structure) {
|
||||
/* private: */
|
||||
|
||||
/* Pointer to (payload of) root node in AVL tree. This field should
|
||||
** really be the AVL tree descriptor (type avl_avl). But (in the
|
||||
** instantiation of the AVL tree generic package used in package) the
|
||||
** AVL tree descriptor simply contains a pointer to the root. So,
|
||||
** whenever a pointer to the AVL tree descriptor is needed, I use the
|
||||
** cast:
|
||||
**
|
||||
** (avl_avl *) &(heap_desc->avl_tree_root)
|
||||
**
|
||||
** (where heap_desc is a pointer to a heap descriptor). This trick
|
||||
** allows me to avoid including cavl_if.h in this external header. */
|
||||
void *avl_tree_root;
|
||||
|
||||
/* Pointer to first byte of last block freed, after any coalescing. */
|
||||
void *last_freed;
|
||||
|
||||
/* public: */
|
||||
|
||||
HMM_UNIQUE(size_bau) num_baus_can_shrink;
|
||||
void *end_of_shrinkable_chunk;
|
||||
}
|
||||
HMM_UNIQUE(descriptor);
|
||||
|
||||
/* Prototypes for externally-callable functions. */
|
||||
|
||||
void HMM_UNIQUE(init)(HMM_UNIQUE(descriptor) *desc);
|
||||
|
||||
void *HMM_UNIQUE(alloc)(
|
||||
HMM_UNIQUE(descriptor) *desc, HMM_UNIQUE(size_aau) num_addr_align_units);
|
||||
|
||||
/* NOT YET IMPLEMENTED */
|
||||
void *HMM_UNIQUE(greedy_alloc)(
|
||||
HMM_UNIQUE(descriptor) *desc, HMM_UNIQUE(size_aau) needed_addr_align_units,
|
||||
HMM_UNIQUE(size_aau) coveted_addr_align_units);
|
||||
|
||||
int HMM_UNIQUE(resize)(
|
||||
HMM_UNIQUE(descriptor) *desc, void *mem,
|
||||
HMM_UNIQUE(size_aau) num_addr_align_units);
|
||||
|
||||
/* NOT YET IMPLEMENTED */
|
||||
int HMM_UNIQUE(greedy_resize)(
|
||||
HMM_UNIQUE(descriptor) *desc, void *mem,
|
||||
HMM_UNIQUE(size_aau) needed_addr_align_units,
|
||||
HMM_UNIQUE(size_aau) coveted_addr_align_units);
|
||||
|
||||
void HMM_UNIQUE(free)(HMM_UNIQUE(descriptor) *desc, void *mem);
|
||||
|
||||
HMM_UNIQUE(size_aau) HMM_UNIQUE(true_size)(void *mem);
|
||||
|
||||
HMM_UNIQUE(size_aau) HMM_UNIQUE(largest_available)(
|
||||
HMM_UNIQUE(descriptor) *desc);
|
||||
|
||||
void HMM_UNIQUE(new_chunk)(
|
||||
HMM_UNIQUE(descriptor) *desc, void *start_of_chunk,
|
||||
HMM_UNIQUE(size_bau) num_block_align_units);
|
||||
|
||||
void HMM_UNIQUE(grow_chunk)(
|
||||
HMM_UNIQUE(descriptor) *desc, void *end_of_chunk,
|
||||
HMM_UNIQUE(size_bau) num_block_align_units);
|
||||
|
||||
/* NOT YET IMPLEMENTED */
|
||||
void HMM_UNIQUE(shrink_chunk)(
|
||||
HMM_UNIQUE(descriptor) *desc,
|
||||
HMM_UNIQUE(size_bau) num_block_align_units);
|
||||
|
||||
#endif /* defined HMM_PROCESS */
|
||||
#endif // VPX_MEM_MEMORY_MANAGER_INCLUDE_HEAPMM_H_
|
@ -1,120 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2010 The WebM project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#ifndef VPX_MEM_MEMORY_MANAGER_INCLUDE_HMM_CNFG_H_
|
||||
#define VPX_MEM_MEMORY_MANAGER_INCLUDE_HMM_CNFG_H_
|
||||
|
||||
/* This code is in the public domain.
|
||||
** Version: 1.1 Author: Walt Karas
|
||||
*/
|
||||
|
||||
/* Configure Heap Memory Manager for processor architecture, compiler,
|
||||
** and desired performance characteristics. This file is included
|
||||
** by heapmm.h, so these definitions can be used by code external to
|
||||
** HMM. You can change the default configuration, and/or create alternate
|
||||
** configuration(s).
|
||||
*/
|
||||
|
||||
/* To allow for multiple configurations of HMM to be used in the same
|
||||
** compilation unit, undefine all preprocessor symbols that will be
|
||||
** defined below.
|
||||
*/
|
||||
#undef HMM_ADDR_ALIGN_UNIT
|
||||
#undef HMM_BLOCK_ALIGN_UNIT
|
||||
#undef HMM_UNIQUE
|
||||
#undef HMM_DESC_PARAM
|
||||
#undef HMM_SYM_TO_STRING
|
||||
#undef HMM_SYM_TO_STRING
|
||||
#undef HMM_AUDIT_FAIL
|
||||
|
||||
/* Turn X into a string after one macro expansion pass of X. This trick
|
||||
** works with both GCC and Visual C++. */
|
||||
#define HMM_SYM_TO_STRING(X) HMM_SYM_TO_STRING(X)
|
||||
#define HMM_SYM_TO_STRING(X) #X
|
||||
|
||||
#ifndef HMM_CNFG_NUM
|
||||
|
||||
/* Default configuration. */
|
||||
|
||||
/* Use hmm_ prefix to avoid identifier conflicts. */
|
||||
#define HMM_UNIQUE(BASE) hmm_ ## BASE
|
||||
|
||||
/* Number of bytes in an Address Alignment Unit (AAU). */
|
||||
// fwg
|
||||
// #define HMM_ADDR_ALIGN_UNIT sizeof(int)
|
||||
#define HMM_ADDR_ALIGN_UNIT 32
|
||||
|
||||
/* Number of AAUs in a Block Alignment Unit (BAU). */
|
||||
#define HMM_BLOCK_ALIGN_UNIT 1
|
||||
|
||||
/* Type of unsigned integer big enough to hold the size of a Block in AAUs. */
|
||||
typedef unsigned long HMM_UNIQUE(size_aau);
|
||||
|
||||
/* Type of unsigned integer big enough to hold the size of a Block/Chunk
|
||||
** in BAUs. The high bit will be robbed. */
|
||||
typedef unsigned long HMM_UNIQUE(size_bau);
|
||||
|
||||
void hmm_dflt_abort(const char *, const char *);
|
||||
|
||||
/* Actions upon a self-audit failure. Must expand to a single complete
|
||||
** statement. If you remove the definition of this macro, no self-auditing
|
||||
** will be performed. */
|
||||
#define HMM_AUDIT_FAIL \
|
||||
hmm_dflt_abort(__FILE__, HMM_SYM_TO_STRING(__LINE__));
|
||||
|
||||
#elif HMM_CNFG_NUM == 0
|
||||
|
||||
/* Definitions for testing. */
|
||||
|
||||
#define HMM_UNIQUE(BASE) thmm_ ## BASE
|
||||
|
||||
#define HMM_ADDR_ALIGN_UNIT sizeof(int)
|
||||
|
||||
#define HMM_BLOCK_ALIGN_UNIT 3
|
||||
|
||||
typedef unsigned HMM_UNIQUE(size_aau);
|
||||
|
||||
typedef unsigned short HMM_UNIQUE(size_bau);
|
||||
|
||||
/* Under this test setup, a long jump is done if there is a self-audit
|
||||
** failure.
|
||||
*/
|
||||
|
||||
extern jmp_buf HMM_UNIQUE(jmp_buf);
|
||||
extern const char *HMM_UNIQUE(fail_file);
|
||||
extern unsigned HMM_UNIQUE(fail_line);
|
||||
|
||||
#define HMM_AUDIT_FAIL \
|
||||
{ HMM_UNIQUE(fail_file) = __FILE__; HMM_UNIQUE(fail_line) = __LINE__; \
|
||||
longjmp(HMM_UNIQUE(jmp_buf), 1); }
|
||||
|
||||
#elif HMM_CNFG_NUM == 1
|
||||
|
||||
/* Put configuration 1 definitions here (if there is a configuration 1). */
|
||||
|
||||
#elif HMM_CNFG_NUM == 2
|
||||
|
||||
/* Put configuration 2 definitions here. */
|
||||
|
||||
#elif HMM_CNFG_NUM == 3
|
||||
|
||||
/* Put configuration 3 definitions here. */
|
||||
|
||||
#elif HMM_CNFG_NUM == 4
|
||||
|
||||
/* Put configuration 4 definitions here. */
|
||||
|
||||
#elif HMM_CNFG_NUM == 5
|
||||
|
||||
/* Put configuration 5 definitions here. */
|
||||
|
||||
#endif
|
||||
|
||||
#endif // VPX_MEM_MEMORY_MANAGER_INCLUDE_HMM_CNFG_H_
|
@ -1,159 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2010 The WebM project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
|
||||
/* This code is in the public domain.
|
||||
** Version: 1.1 Author: Walt Karas
|
||||
*/
|
||||
|
||||
#ifndef VPX_MEM_MEMORY_MANAGER_INCLUDE_HMM_INTRNL_H_
|
||||
#define VPX_MEM_MEMORY_MANAGER_INCLUDE_HMM_INTRNL_H_
|
||||
|
||||
#ifdef __uClinux__
|
||||
# include <lddk.h>
|
||||
#endif
|
||||
|
||||
#include "heapmm.h"
|
||||
|
||||
#define U(BASE) HMM_UNIQUE(BASE)
|
||||
|
||||
/* Mask of high bit of variable of size_bau type. */
|
||||
#define HIGH_BIT_BAU_SIZE \
|
||||
((U(size_bau)) ~ (((U(size_bau)) ~ (U(size_bau)) 0) >> 1))
|
||||
|
||||
/* Add a given number of AAUs to pointer. */
|
||||
#define AAUS_FORWARD(PTR, AAU_OFFSET) \
|
||||
(((char *) (PTR)) + ((AAU_OFFSET) * ((U(size_aau)) HMM_ADDR_ALIGN_UNIT)))
|
||||
|
||||
/* Subtract a given number of AAUs from pointer. */
|
||||
#define AAUS_BACKWARD(PTR, AAU_OFFSET) \
|
||||
(((char *) (PTR)) - ((AAU_OFFSET) * ((U(size_aau)) HMM_ADDR_ALIGN_UNIT)))
|
||||
|
||||
/* Add a given number of BAUs to a pointer. */
|
||||
#define BAUS_FORWARD(PTR, BAU_OFFSET) \
|
||||
AAUS_FORWARD((PTR), (BAU_OFFSET) * ((U(size_aau)) HMM_BLOCK_ALIGN_UNIT))
|
||||
|
||||
/* Subtract a given number of BAUs to a pointer. */
|
||||
#define BAUS_BACKWARD(PTR, BAU_OFFSET) \
|
||||
AAUS_BACKWARD((PTR), (BAU_OFFSET) * ((U(size_aau)) HMM_BLOCK_ALIGN_UNIT))
|
||||
|
||||
typedef struct head_struct {
|
||||
/* Sizes in Block Alignment Units. */
|
||||
HMM_UNIQUE(size_bau) previous_block_size, block_size;
|
||||
}
|
||||
head_record;
|
||||
|
||||
typedef struct ptr_struct {
|
||||
struct ptr_struct *self, *prev, *next;
|
||||
}
|
||||
ptr_record;
|
||||
|
||||
/* Divide and round up any fraction to the next whole number. */
|
||||
#define DIV_ROUND_UP(NUMER, DENOM) (((NUMER) + (DENOM) - 1) / (DENOM))
|
||||
|
||||
/* Number of AAUs in a block head. */
|
||||
#define HEAD_AAUS DIV_ROUND_UP(sizeof(head_record), HMM_ADDR_ALIGN_UNIT)
|
||||
|
||||
/* Number of AAUs in a block pointer record. */
|
||||
#define PTR_RECORD_AAUS DIV_ROUND_UP(sizeof(ptr_record), HMM_ADDR_ALIGN_UNIT)
|
||||
|
||||
/* Number of BAUs in a dummy end record (at end of chunk). */
|
||||
#define DUMMY_END_BLOCK_BAUS DIV_ROUND_UP(HEAD_AAUS, HMM_BLOCK_ALIGN_UNIT)
|
||||
|
||||
/* Minimum number of BAUs in a block (allowing room for the pointer record. */
|
||||
#define MIN_BLOCK_BAUS \
|
||||
DIV_ROUND_UP(HEAD_AAUS + PTR_RECORD_AAUS, HMM_BLOCK_ALIGN_UNIT)
|
||||
|
||||
/* Return number of BAUs in block (masking off high bit containing block
|
||||
** status). */
|
||||
#define BLOCK_BAUS(HEAD_PTR) \
|
||||
(((head_record *) (HEAD_PTR))->block_size & ~HIGH_BIT_BAU_SIZE)
|
||||
|
||||
/* Return number of BAUs in previous block (masking off high bit containing
|
||||
** block status). */
|
||||
#define PREV_BLOCK_BAUS(HEAD_PTR) \
|
||||
(((head_record *) (HEAD_PTR))->previous_block_size & ~HIGH_BIT_BAU_SIZE)
|
||||
|
||||
/* Set number of BAUs in previous block, preserving high bit containing
|
||||
** block status. */
|
||||
#define SET_PREV_BLOCK_BAUS(HEAD_PTR, N_BAUS) \
|
||||
{ register head_record *h_ptr = (head_record *) (HEAD_PTR); \
|
||||
h_ptr->previous_block_size &= HIGH_BIT_BAU_SIZE; \
|
||||
h_ptr->previous_block_size |= (N_BAUS); }
|
||||
|
||||
/* Convert pointer to pointer record of block to pointer to block's head
|
||||
** record. */
|
||||
#define PTR_REC_TO_HEAD(PTR_REC_PTR) \
|
||||
((head_record *) AAUS_BACKWARD(PTR_REC_PTR, HEAD_AAUS))
|
||||
|
||||
/* Convert pointer to block head to pointer to block's pointer record. */
|
||||
#define HEAD_TO_PTR_REC(HEAD_PTR) \
|
||||
((ptr_record *) AAUS_FORWARD(HEAD_PTR, HEAD_AAUS))
|
||||
|
||||
/* Returns non-zero if block is allocated. */
|
||||
#define IS_BLOCK_ALLOCATED(HEAD_PTR) \
|
||||
(((((head_record *) (HEAD_PTR))->block_size | \
|
||||
((head_record *) (HEAD_PTR))->previous_block_size) & \
|
||||
HIGH_BIT_BAU_SIZE) == 0)
|
||||
|
||||
#define MARK_BLOCK_ALLOCATED(HEAD_PTR) \
|
||||
{ register head_record *h_ptr = (head_record *) (HEAD_PTR); \
|
||||
h_ptr->block_size &= ~HIGH_BIT_BAU_SIZE; \
|
||||
h_ptr->previous_block_size &= ~HIGH_BIT_BAU_SIZE; }
|
||||
|
||||
/* Mark a block as free when it is not the first block in a bin (and
|
||||
** therefore not a node in the AVL tree). */
|
||||
#define MARK_SUCCESSIVE_BLOCK_IN_FREE_BIN(HEAD_PTR) \
|
||||
{ register head_record *h_ptr = (head_record *) (HEAD_PTR); \
|
||||
h_ptr->block_size |= HIGH_BIT_BAU_SIZE; }
|
||||
|
||||
/* Prototypes for internal functions implemented in one file and called in
|
||||
** another.
|
||||
*/
|
||||
|
||||
void U(into_free_collection)(U(descriptor) *desc, head_record *head_ptr);
|
||||
|
||||
void U(out_of_free_collection)(U(descriptor) *desc, head_record *head_ptr);
|
||||
|
||||
void *U(alloc_from_bin)(
|
||||
U(descriptor) *desc, ptr_record *bin_front_ptr, U(size_bau) n_baus);
|
||||
|
||||
#ifdef HMM_AUDIT_FAIL
|
||||
|
||||
/* Simply contains a reference to the HMM_AUDIT_FAIL macro and a
|
||||
** dummy return. */
|
||||
int U(audit_block_fail_dummy_return)(void);
|
||||
|
||||
|
||||
/* Auditing a block consists of checking that the size in its head
|
||||
** matches the previous block size in the head of the next block. */
|
||||
#define AUDIT_BLOCK_AS_EXPR(HEAD_PTR) \
|
||||
((BLOCK_BAUS(HEAD_PTR) == \
|
||||
PREV_BLOCK_BAUS(BAUS_FORWARD(HEAD_PTR, BLOCK_BAUS(HEAD_PTR)))) ? \
|
||||
0 : U(audit_block_fail_dummy_return)())
|
||||
|
||||
#define AUDIT_BLOCK(HEAD_PTR) \
|
||||
{ void *h_ptr = (HEAD_PTR); AUDIT_BLOCK_AS_EXPR(h_ptr); }
|
||||
|
||||
#endif
|
||||
|
||||
/* Interface to AVL tree generic package instantiation. */
|
||||
|
||||
#define AVL_UNIQUE(BASE) U(avl_ ## BASE)
|
||||
|
||||
#define AVL_HANDLE ptr_record *
|
||||
|
||||
#define AVL_KEY U(size_bau)
|
||||
|
||||
#define AVL_MAX_DEPTH 64
|
||||
|
||||
#include "cavl_if.h"
|
||||
|
||||
#endif // VPX_MEM_MEMORY_MANAGER_INCLUDE_HMM_INTRNL_H_
|
@ -27,30 +27,6 @@ static unsigned long g_alloc_count = 0;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if CONFIG_MEM_MANAGER
|
||||
# include "heapmm.h"
|
||||
# include "hmm_intrnl.h"
|
||||
|
||||
# define SHIFT_HMM_ADDR_ALIGN_UNIT 5
|
||||
# define TOTAL_MEMORY_TO_ALLOCATE 20971520 /* 20 * 1024 * 1024 */
|
||||
|
||||
# define MM_DYNAMIC_MEMORY 1
|
||||
# if MM_DYNAMIC_MEMORY
|
||||
static unsigned char *g_p_mng_memory_raw = NULL;
|
||||
static unsigned char *g_p_mng_memory = NULL;
|
||||
# else
|
||||
static unsigned char g_p_mng_memory[TOTAL_MEMORY_TO_ALLOCATE];
|
||||
# endif
|
||||
|
||||
static size_t g_mm_memory_size = TOTAL_MEMORY_TO_ALLOCATE;
|
||||
|
||||
static hmm_descriptor hmm_d;
|
||||
static int g_mng_memory_allocated = 0;
|
||||
|
||||
static int vpx_mm_create_heap_memory();
|
||||
static void *vpx_mm_realloc(void *memblk, size_t size);
|
||||
#endif /*CONFIG_MEM_MANAGER*/
|
||||
|
||||
#if USE_GLOBAL_FUNCTION_POINTERS
|
||||
struct GLOBAL_FUNC_POINTERS {
|
||||
g_malloc_func g_malloc;
|
||||
@ -85,46 +61,11 @@ unsigned int vpx_mem_get_version() {
|
||||
return ver;
|
||||
}
|
||||
|
||||
int vpx_mem_set_heap_size(size_t size) {
|
||||
int ret = -1;
|
||||
|
||||
#if CONFIG_MEM_MANAGER
|
||||
#if MM_DYNAMIC_MEMORY
|
||||
|
||||
if (!g_mng_memory_allocated && size) {
|
||||
g_mm_memory_size = size;
|
||||
ret = 0;
|
||||
} else
|
||||
ret = -3;
|
||||
|
||||
#else
|
||||
ret = -2;
|
||||
#endif
|
||||
#else
|
||||
(void)size;
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void *vpx_memalign(size_t align, size_t size) {
|
||||
void *addr,
|
||||
* x = NULL;
|
||||
|
||||
#if CONFIG_MEM_MANAGER
|
||||
int number_aau;
|
||||
|
||||
if (vpx_mm_create_heap_memory() < 0) {
|
||||
_P(printf("[vpx][mm] ERROR vpx_memalign() Couldn't create memory for Heap.\n");)
|
||||
}
|
||||
|
||||
number_aau = ((size + align - 1 + ADDRESS_STORAGE_SIZE) >>
|
||||
SHIFT_HMM_ADDR_ALIGN_UNIT) + 1;
|
||||
|
||||
addr = hmm_alloc(&hmm_d, number_aau);
|
||||
#else
|
||||
addr = VPX_MALLOC_L(size + align - 1 + ADDRESS_STORAGE_SIZE);
|
||||
#endif /*CONFIG_MEM_MANAGER*/
|
||||
|
||||
if (addr) {
|
||||
x = align_addr((unsigned char *)addr + ADDRESS_STORAGE_SIZE, (int)align);
|
||||
@ -171,11 +112,7 @@ void *vpx_realloc(void *memblk, size_t size) {
|
||||
addr = (void *)(((size_t *)memblk)[-1]);
|
||||
memblk = NULL;
|
||||
|
||||
#if CONFIG_MEM_MANAGER
|
||||
new_addr = vpx_mm_realloc(addr, size + align + ADDRESS_STORAGE_SIZE);
|
||||
#else
|
||||
new_addr = VPX_REALLOC_L(addr, size + align + ADDRESS_STORAGE_SIZE);
|
||||
#endif
|
||||
|
||||
if (new_addr) {
|
||||
addr = new_addr;
|
||||
@ -193,11 +130,7 @@ void *vpx_realloc(void *memblk, size_t size) {
|
||||
void vpx_free(void *memblk) {
|
||||
if (memblk) {
|
||||
void *addr = (void *)(((size_t *)memblk)[-1]);
|
||||
#if CONFIG_MEM_MANAGER
|
||||
hmm_free(&hmm_d, addr);
|
||||
#else
|
||||
VPX_FREE_L(addr);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@ -494,108 +427,6 @@ void *vpx_memmove(void *dest, const void *src, size_t count) {
|
||||
return VPX_MEMMOVE_L(dest, src, count);
|
||||
}
|
||||
|
||||
#if CONFIG_MEM_MANAGER
|
||||
|
||||
static int vpx_mm_create_heap_memory() {
|
||||
int i_rv = 0;
|
||||
|
||||
if (!g_mng_memory_allocated) {
|
||||
#if MM_DYNAMIC_MEMORY
|
||||
g_p_mng_memory_raw =
|
||||
(unsigned char *)malloc(g_mm_memory_size + HMM_ADDR_ALIGN_UNIT);
|
||||
|
||||
if (g_p_mng_memory_raw) {
|
||||
g_p_mng_memory = (unsigned char *)((((unsigned int)g_p_mng_memory_raw) +
|
||||
HMM_ADDR_ALIGN_UNIT - 1) &
|
||||
-(int)HMM_ADDR_ALIGN_UNIT);
|
||||
|
||||
_P(printf("[vpx][mm] total memory size:%d g_p_mng_memory_raw:0x%x g_p_mng_memory:0x%x\n"
|
||||
, g_mm_memory_size + HMM_ADDR_ALIGN_UNIT
|
||||
, (unsigned int)g_p_mng_memory_raw
|
||||
, (unsigned int)g_p_mng_memory);)
|
||||
} else {
|
||||
_P(printf("[vpx][mm] Couldn't allocate memory:%d for vpx memory manager.\n"
|
||||
, g_mm_memory_size);)
|
||||
|
||||
i_rv = -1;
|
||||
}
|
||||
|
||||
if (g_p_mng_memory)
|
||||
#endif
|
||||
{
|
||||
int chunk_size = 0;
|
||||
|
||||
g_mng_memory_allocated = 1;
|
||||
|
||||
hmm_init(&hmm_d);
|
||||
|
||||
chunk_size = g_mm_memory_size >> SHIFT_HMM_ADDR_ALIGN_UNIT;
|
||||
|
||||
chunk_size -= DUMMY_END_BLOCK_BAUS;
|
||||
|
||||
_P(printf("[vpx][mm] memory size:%d for vpx memory manager. g_p_mng_memory:0x%x chunk_size:%d\n"
|
||||
, g_mm_memory_size
|
||||
, (unsigned int)g_p_mng_memory
|
||||
, chunk_size);)
|
||||
|
||||
hmm_new_chunk(&hmm_d, (void *)g_p_mng_memory, chunk_size);
|
||||
}
|
||||
|
||||
#if MM_DYNAMIC_MEMORY
|
||||
else {
|
||||
_P(printf("[vpx][mm] Couldn't allocate memory:%d for vpx memory manager.\n"
|
||||
, g_mm_memory_size);)
|
||||
|
||||
i_rv = -1;
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
return i_rv;
|
||||
}
|
||||
|
||||
static void *vpx_mm_realloc(void *memblk, size_t size) {
|
||||
void *p_ret = NULL;
|
||||
|
||||
if (vpx_mm_create_heap_memory() < 0) {
|
||||
_P(printf("[vpx][mm] ERROR vpx_mm_realloc() Couldn't create memory for Heap.\n");)
|
||||
} else {
|
||||
int i_rv = 0;
|
||||
int old_num_aaus;
|
||||
int new_num_aaus;
|
||||
|
||||
old_num_aaus = hmm_true_size(memblk);
|
||||
new_num_aaus = (size >> SHIFT_HMM_ADDR_ALIGN_UNIT) + 1;
|
||||
|
||||
if (old_num_aaus == new_num_aaus) {
|
||||
p_ret = memblk;
|
||||
} else {
|
||||
i_rv = hmm_resize(&hmm_d, memblk, new_num_aaus);
|
||||
|
||||
if (i_rv == 0) {
|
||||
p_ret = memblk;
|
||||
} else {
|
||||
/* Error. Try to malloc and then copy data. */
|
||||
void *p_from_malloc;
|
||||
|
||||
new_num_aaus = (size >> SHIFT_HMM_ADDR_ALIGN_UNIT) + 1;
|
||||
p_from_malloc = hmm_alloc(&hmm_d, new_num_aaus);
|
||||
|
||||
if (p_from_malloc) {
|
||||
vpx_memcpy(p_from_malloc, memblk, size);
|
||||
hmm_free(&hmm_d, memblk);
|
||||
|
||||
p_ret = p_from_malloc;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return p_ret;
|
||||
}
|
||||
#endif /*CONFIG_MEM_MANAGER*/
|
||||
|
||||
#if USE_GLOBAL_FUNCTION_POINTERS
|
||||
# if CONFIG_MEM_TRACKER
|
||||
extern int vpx_memory_tracker_set_functions(g_malloc_func g_malloc_l
|
||||
|
@ -53,18 +53,6 @@ extern "C" {
|
||||
*/
|
||||
unsigned int vpx_mem_get_version(void);
|
||||
|
||||
/*
|
||||
vpx_mem_set_heap_size(size_t size)
|
||||
size - size in bytes for the memory manager to allocate for its heap
|
||||
Sets the memory manager's initial heap size
|
||||
Return:
|
||||
0: on success
|
||||
-1: if memory manager calls have not been included in the vpx_mem lib
|
||||
-2: if the memory manager has been compiled to use static memory
|
||||
-3: if the memory manager has already allocated its heap
|
||||
*/
|
||||
int vpx_mem_set_heap_size(size_t size);
|
||||
|
||||
void *vpx_memalign(size_t align, size_t size);
|
||||
void *vpx_malloc(size_t size);
|
||||
void *vpx_calloc(size_t num, size_t size);
|
||||
|
@ -5,18 +5,3 @@ MEM_SRCS-yes += include/vpx_mem_intrnl.h
|
||||
|
||||
MEM_SRCS-$(CONFIG_MEM_TRACKER) += vpx_mem_tracker.c
|
||||
MEM_SRCS-$(CONFIG_MEM_TRACKER) += include/vpx_mem_tracker.h
|
||||
|
||||
MEM_SRCS-$(CONFIG_MEM_MANAGER) += memory_manager/hmm_true.c
|
||||
MEM_SRCS-$(CONFIG_MEM_MANAGER) += memory_manager/hmm_resize.c
|
||||
MEM_SRCS-$(CONFIG_MEM_MANAGER) += memory_manager/hmm_shrink.c
|
||||
MEM_SRCS-$(CONFIG_MEM_MANAGER) += memory_manager/hmm_largest.c
|
||||
MEM_SRCS-$(CONFIG_MEM_MANAGER) += memory_manager/hmm_dflt_abort.c
|
||||
MEM_SRCS-$(CONFIG_MEM_MANAGER) += memory_manager/hmm_base.c
|
||||
MEM_SRCS-$(CONFIG_MEM_MANAGER) += memory_manager/include
|
||||
MEM_SRCS-$(CONFIG_MEM_MANAGER) += memory_manager/include/hmm_intrnl.h
|
||||
MEM_SRCS-$(CONFIG_MEM_MANAGER) += memory_manager/include/cavl_if.h
|
||||
MEM_SRCS-$(CONFIG_MEM_MANAGER) += memory_manager/include/hmm_cnfg.h
|
||||
MEM_SRCS-$(CONFIG_MEM_MANAGER) += memory_manager/include/heapmm.h
|
||||
MEM_SRCS-$(CONFIG_MEM_MANAGER) += memory_manager/include/cavl_impl.h
|
||||
MEM_SRCS-$(CONFIG_MEM_MANAGER) += memory_manager/hmm_grow.c
|
||||
MEM_SRCS-$(CONFIG_MEM_MANAGER) += memory_manager/hmm_alloc.c
|
||||
|
Loading…
x
Reference in New Issue
Block a user