1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "base/allocator/allocator_extension.h" 6 7 #include "base/logging.h" 8 9 namespace base { 10 namespace allocator { 11 GetAllocatorWasteSize(size_t * size)12bool GetAllocatorWasteSize(size_t* size) { 13 thunks::GetAllocatorWasteSizeFunction get_allocator_waste_size_function = 14 thunks::GetGetAllocatorWasteSizeFunction(); 15 return get_allocator_waste_size_function != NULL && 16 get_allocator_waste_size_function(size); 17 } 18 GetStats(char * buffer,int buffer_length)19void GetStats(char* buffer, int buffer_length) { 20 DCHECK_GT(buffer_length, 0); 21 thunks::GetStatsFunction get_stats_function = thunks::GetGetStatsFunction(); 22 if (get_stats_function) 23 get_stats_function(buffer, buffer_length); 24 else 25 buffer[0] = '\0'; 26 } 27 ReleaseFreeMemory()28void ReleaseFreeMemory() { 29 thunks::ReleaseFreeMemoryFunction release_free_memory_function = 30 thunks::GetReleaseFreeMemoryFunction(); 31 if (release_free_memory_function) 32 release_free_memory_function(); 33 } 34 SetGetAllocatorWasteSizeFunction(thunks::GetAllocatorWasteSizeFunction get_allocator_waste_size_function)35void SetGetAllocatorWasteSizeFunction( 36 thunks::GetAllocatorWasteSizeFunction get_allocator_waste_size_function) { 37 DCHECK_EQ(thunks::GetGetAllocatorWasteSizeFunction(), 38 reinterpret_cast<thunks::GetAllocatorWasteSizeFunction>(NULL)); 39 thunks::SetGetAllocatorWasteSizeFunction(get_allocator_waste_size_function); 40 } 41 SetGetStatsFunction(thunks::GetStatsFunction get_stats_function)42void SetGetStatsFunction(thunks::GetStatsFunction get_stats_function) { 43 DCHECK_EQ(thunks::GetGetStatsFunction(), 44 reinterpret_cast<thunks::GetStatsFunction>(NULL)); 45 thunks::SetGetStatsFunction(get_stats_function); 46 } 47 SetReleaseFreeMemoryFunction(thunks::ReleaseFreeMemoryFunction release_free_memory_function)48void SetReleaseFreeMemoryFunction( 49 thunks::ReleaseFreeMemoryFunction release_free_memory_function) { 50 DCHECK_EQ(thunks::GetReleaseFreeMemoryFunction(), 51 reinterpret_cast<thunks::ReleaseFreeMemoryFunction>(NULL)); 52 thunks::SetReleaseFreeMemoryFunction(release_free_memory_function); 53 } 54 55 } // namespace allocator 56 } // namespace base 57