| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 | 11 |
| 12 /* This code is in the public domain. | 12 /* This code is in the public domain. |
| 13 ** Version: 1.1 Author: Walt Karas | 13 ** Version: 1.1 Author: Walt Karas |
| 14 */ | 14 */ |
| 15 | 15 |
| 16 #include "hmm_intrnl.h" | 16 #include "hmm_intrnl.h" |
| 17 | 17 |
| 18 void *U(alloc)(U(descriptor) *desc, U(size_aau) n) | 18 void *U(alloc)(U(descriptor) *desc, U(size_aau) n) { |
| 19 { | |
| 20 #ifdef HMM_AUDIT_FAIL | 19 #ifdef HMM_AUDIT_FAIL |
| 21 | 20 |
| 22 if (desc->avl_tree_root) | 21 if (desc->avl_tree_root) |
| 23 AUDIT_BLOCK(PTR_REC_TO_HEAD(desc->avl_tree_root)) | 22 AUDIT_BLOCK(PTR_REC_TO_HEAD(desc->avl_tree_root)) |
| 24 #endif | 23 #endif |
| 25 | 24 |
| 26 if (desc->last_freed) | 25 if (desc->last_freed) { |
| 27 { | |
| 28 #ifdef HMM_AUDIT_FAIL | 26 #ifdef HMM_AUDIT_FAIL |
| 29 AUDIT_BLOCK(desc->last_freed) | 27 AUDIT_BLOCK(desc->last_freed) |
| 30 #endif | 28 #endif |
| 31 | 29 |
| 32 U(into_free_collection)(desc, (head_record *)(desc->last_freed)); | 30 U(into_free_collection)(desc, (head_record *)(desc->last_freed)); |
| 33 | 31 |
| 34 desc->last_freed = 0; | 32 desc->last_freed = 0; |
| 35 } | 33 } |
| 36 | 34 |
| 37 /* Add space for block header. */ | 35 /* Add space for block header. */ |
| 38 n += HEAD_AAUS; | 36 n += HEAD_AAUS; |
| 39 | 37 |
| 40 /* Convert n from number of address alignment units to block alignment | 38 /* Convert n from number of address alignment units to block alignment |
| 41 ** units. */ | 39 ** units. */ |
| 42 n = DIV_ROUND_UP(n, HMM_BLOCK_ALIGN_UNIT); | 40 n = DIV_ROUND_UP(n, HMM_BLOCK_ALIGN_UNIT); |
| 43 | 41 |
| 44 if (n < MIN_BLOCK_BAUS) | 42 if (n < MIN_BLOCK_BAUS) |
| 45 n = MIN_BLOCK_BAUS; | 43 n = MIN_BLOCK_BAUS; |
| 46 | 44 |
| 47 { | 45 { |
| 48 /* Search for the first node of the bin containing the smallest | 46 /* Search for the first node of the bin containing the smallest |
| 49 ** block big enough to satisfy request. */ | 47 ** block big enough to satisfy request. */ |
| 50 ptr_record *ptr_rec_ptr = | 48 ptr_record *ptr_rec_ptr = |
| 51 U(avl_search)( | 49 U(avl_search)( |
| 52 (U(avl_avl) *) & (desc->avl_tree_root), (U(size_bau)) n, | 50 (U(avl_avl) *) & (desc->avl_tree_root), (U(size_bau)) n, |
| 53 AVL_GREATER_EQUAL); | 51 AVL_GREATER_EQUAL); |
| 54 | 52 |
| 55 /* If an approprate bin is found, satisfy the allocation request, | 53 /* If an approprate bin is found, satisfy the allocation request, |
| 56 ** otherwise return null pointer. */ | 54 ** otherwise return null pointer. */ |
| 57 return(ptr_rec_ptr ? | 55 return(ptr_rec_ptr ? |
| 58 U(alloc_from_bin)(desc, ptr_rec_ptr, (U(size_bau)) n) : 0); | 56 U(alloc_from_bin)(desc, ptr_rec_ptr, (U(size_bau)) n) : 0); |
| 59 } | 57 } |
| 60 } | 58 } |
| OLD | NEW |