Commit e5eda53e authored by James Zern's avatar James Zern

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
parent 305492c3
......@@ -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
......
/*
* 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);
}
}
This diff is collapsed.
/*
* 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);
}
/*
* 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
}
/*
* 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);
}
/*
* 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);
}
/*
* 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
}
}
/*
* 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);
}
/*
* 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);