1/*
2 * Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
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 PAGED_MEM_POOL_H
16#define PAGED_MEM_POOL_H
17
18#include <set>
19#include <vector>
20#include "ftrace_namespace.h"
21
22FTRACE_NS_BEGIN
23class PagedMemPool {
24public:
25    PagedMemPool(size_t pagePerBlock = 1, size_t maxCacheSize = 0);
26    ~PagedMemPool();
27
28    void* Allocate();
29
30    bool Recycle(void* block);
31
32    size_t GetBlockSize() const;
33
34private:
35    DISALLOW_COPY_AND_MOVE(PagedMemPool);
36    bool Free(void* block);
37    bool Valid(void* block);
38
39private:
40    size_t blockSize_ = 1;
41    size_t maxCacheSize_ = 0;
42    std::vector<void*> freeList_;
43    std::set<void*> blockSet_;
44};
45FTRACE_NS_END
46
47#endif // PAGED_MEM_POOL_H