1 /** 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://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, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef PANDA_POOL_MANAGER_H 16 #define PANDA_POOL_MANAGER_H 17 18 #include "malloc_mem_pool.h" 19 #include "mmap_mem_pool.h" 20 #include "arena-inl.h" 21 22 namespace panda { 23 enum class PoolType { MALLOC, MMAP }; 24 25 class PoolManager { 26 public: 27 ~PoolManager() = default; 28 PoolManager() = default; 29 DEFAULT_NOEXCEPT_MOVE_SEMANTIC(PoolManager); 30 DEFAULT_COPY_SEMANTIC(PoolManager); 31 static void Initialize(PoolType type = PoolType::MMAP); 32 static Arena *AllocArena(size_t size, SpaceType space_type, AllocatorType allocator_type, 33 const void *allocator_addr = nullptr); 34 static void FreeArena(Arena *arena); 35 static MmapMemPool *GetMmapMemPool(); 36 static MallocMemPool *GetMallocMemPool(); 37 38 static void Finalize(); 39 40 private: 41 static bool is_initialized; 42 static PoolType pool_type; 43 static MallocMemPool *malloc_mem_pool; 44 static MmapMemPool *mmap_mem_pool; 45 }; 46 47 } // namespace panda 48 49 #endif // PANDA_POOL_MANAGER_H 50