• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #ifndef LIBPANDABASE_MEM_POOL_MANAGER_H
17 #define LIBPANDABASE_MEM_POOL_MANAGER_H
18 
19 #include "malloc_mem_pool.h"
20 #include "mmap_mem_pool.h"
21 #include "arena-inl.h"
22 
23 namespace panda {
24 enum class PoolType { MALLOC, MMAP };
25 
26 class PoolManager {
27 public:
28     ~PoolManager() = default;
29     PoolManager() = default;
30     DEFAULT_NOEXCEPT_MOVE_SEMANTIC(PoolManager);
31     DEFAULT_COPY_SEMANTIC(PoolManager);
32     static void Initialize(PoolType type = PoolType::MMAP);
33     static Arena *AllocArena(size_t size, SpaceType space_type, AllocatorType allocator_type,
34                              const void *allocator_addr = nullptr);
35     static void FreeArena(Arena *arena);
36     static MmapMemPool *GetMmapMemPool();
37     static MallocMemPool *GetMallocMemPool();
38 
39     static void Finalize();
40 
41 private:
42     static bool is_initialized;
43     static PoolType pool_type;
44     static MallocMemPool *malloc_mem_pool;
45     static MmapMemPool *mmap_mem_pool;
46 };
47 
48 }  // namespace panda
49 
50 #endif  // LIBPANDABASE_MEM_POOL_MANAGER_H
51