blob: bcfe89beb0ea7339bc52b38621bb3d5094110b4f [file] [log] [blame]
[email protected]237a14852012-04-28 02:56:381// 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
9namespace base {
10namespace allocator {
11
[email protected]3b8759592012-12-07 12:19:5112bool 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);
[email protected]094c8932012-09-17 11:44:1017}
18
[email protected]237a14852012-04-28 02:56:3819void GetStats(char* buffer, int buffer_length) {
20 DCHECK_GT(buffer_length, 0);
[email protected]3b8759592012-12-07 12:19:5121 thunks::GetStatsFunction get_stats_function = thunks::GetGetStatsFunction();
[email protected]094c8932012-09-17 11:44:1022 if (get_stats_function)
[email protected]237a14852012-04-28 02:56:3823 get_stats_function(buffer, buffer_length);
24 else
25 buffer[0] = '\0';
26}
27
28void ReleaseFreeMemory() {
[email protected]094c8932012-09-17 11:44:1029 thunks::ReleaseFreeMemoryFunction release_free_memory_function =
[email protected]3b8759592012-12-07 12:19:5130 thunks::GetReleaseFreeMemoryFunction();
[email protected]094c8932012-09-17 11:44:1031 if (release_free_memory_function)
[email protected]237a14852012-04-28 02:56:3832 release_free_memory_function();
33}
34
[email protected]3b8759592012-12-07 12:19:5135void 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);
[email protected]094c8932012-09-17 11:44:1040}
41
42void SetGetStatsFunction(thunks::GetStatsFunction get_stats_function) {
[email protected]3b8759592012-12-07 12:19:5143 DCHECK_EQ(thunks::GetGetStatsFunction(),
[email protected]094c8932012-09-17 11:44:1044 reinterpret_cast<thunks::GetStatsFunction>(NULL));
[email protected]3b8759592012-12-07 12:19:5145 thunks::SetGetStatsFunction(get_stats_function);
[email protected]237a14852012-04-28 02:56:3846}
47
48void SetReleaseFreeMemoryFunction(
[email protected]094c8932012-09-17 11:44:1049 thunks::ReleaseFreeMemoryFunction release_free_memory_function) {
[email protected]3b8759592012-12-07 12:19:5150 DCHECK_EQ(thunks::GetReleaseFreeMemoryFunction(),
[email protected]094c8932012-09-17 11:44:1051 reinterpret_cast<thunks::ReleaseFreeMemoryFunction>(NULL));
[email protected]3b8759592012-12-07 12:19:5152 thunks::SetReleaseFreeMemoryFunction(release_free_memory_function);
[email protected]237a14852012-04-28 02:56:3853}
54
ssid09434092015-10-26 23:05:0455void SetGetNumericPropertyFunction(
56 thunks::GetNumericPropertyFunction get_numeric_property_function) {
57 DCHECK_EQ(thunks::GetGetNumericPropertyFunction(),
58 reinterpret_cast<thunks::GetNumericPropertyFunction>(NULL));
59 thunks::SetGetNumericPropertyFunction(get_numeric_property_function);
60}
61
[email protected]237a14852012-04-28 02:56:3862} // namespace allocator
63} // namespace base