2010-05-18 17:58:33 +02:00
|
|
|
/*
|
2010-09-09 14:16:39 +02:00
|
|
|
* Copyright (c) 2010 The WebM project authors. All Rights Reserved.
|
2010-05-18 17:58:33 +02:00
|
|
|
*
|
2010-06-18 18:39:21 +02:00
|
|
|
* Use of this source code is governed by a BSD-style license
|
2010-06-04 22:19:40 +02:00
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
2010-06-18 18:39:21 +02:00
|
|
|
* in the file PATENTS. All contributing project authors may
|
2010-06-04 22:19:40 +02:00
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
2010-05-18 17:58:33 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/* This code is in the public domain.
|
|
|
|
** Version: 1.1 Author: Walt Karas
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "hmm_intrnl.h"
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
void *U(alloc)(U(descriptor) *desc, U(size_aau) n) {
|
2010-05-18 17:58:33 +02:00
|
|
|
#ifdef HMM_AUDIT_FAIL
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (desc->avl_tree_root)
|
|
|
|
AUDIT_BLOCK(PTR_REC_TO_HEAD(desc->avl_tree_root))
|
2010-05-18 17:58:33 +02:00
|
|
|
#endif
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (desc->last_freed) {
|
2010-05-18 17:58:33 +02:00
|
|
|
#ifdef HMM_AUDIT_FAIL
|
2012-07-14 00:21:29 +02:00
|
|
|
AUDIT_BLOCK(desc->last_freed)
|
2010-05-18 17:58:33 +02:00
|
|
|
#endif
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
U(into_free_collection)(desc, (head_record *)(desc->last_freed));
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
desc->last_freed = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
/* 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);
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|