1 // Copyright 2024 The Pigweed Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not 4 // use this file except in compliance with the License. You may obtain a copy of 5 // the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 // License for the specific language governing permissions and limitations under 13 // the License. 14 15 #include "pw_allocator/dual_first_fit_block_allocator.h" 16 17 #include "pw_malloc/config.h" 18 #include "pw_malloc/malloc.h" 19 20 namespace pw::malloc { 21 namespace { 22 23 using DualFirstFitBlockAllocator = 24 ::pw::allocator::DualFirstFitBlockAllocator<PW_MALLOC_BLOCK_OFFSET_TYPE, 25 PW_MALLOC_BLOCK_POISON_INTERVAL, 26 PW_MALLOC_BLOCK_ALIGNMENT>; 27 GetDualFirstFitBlockAllocator()28DualFirstFitBlockAllocator& GetDualFirstFitBlockAllocator() { 29 static DualFirstFitBlockAllocator system_allocator; 30 return system_allocator; 31 } 32 33 } // namespace 34 GetSystemAllocator()35Allocator* GetSystemAllocator() { 36 auto& system_allocator = GetDualFirstFitBlockAllocator(); 37 return &system_allocator; 38 } 39 InitSystemAllocator(ByteSpan heap)40void InitSystemAllocator(ByteSpan heap) { 41 auto& system_allocator = GetDualFirstFitBlockAllocator(); 42 system_allocator.set_threshold(PW_MALLOC_DUAL_FIRST_FIT_THRESHOLD); 43 system_allocator.Init(heap); 44 } 45 46 } // namespace pw::malloc 47