]> git.ipfire.org Git - thirdparty/squid.git/blob - src/mem/PoolChunked.h
Maintenance: automate header guards 2/3 (#1655)
[thirdparty/squid.git] / src / mem / PoolChunked.h
1 /*
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9 #ifndef SQUID_SRC_MEM_POOLCHUNKED_H
10 #define SQUID_SRC_MEM_POOLCHUNKED_H
11
12 #include "mem/Allocator.h"
13 #include "splay.h"
14
15 #define MEM_CHUNK_SIZE 4 * 4096 /* 16KB ... 4 * VM_PAGE_SZ */
16 #define MEM_CHUNK_MAX_SIZE 256 * 1024 /* 2MB */
17
18 class MemChunk;
19
20 /// \ingroup MemPoolsAPI
21 class MemPoolChunked : public Mem::Allocator
22 {
23 public:
24 friend class MemChunk;
25 MemPoolChunked(const char *label, size_t obj_size);
26 ~MemPoolChunked() override;
27 void convertFreeCacheToChunkFreeCache();
28 void createChunk();
29 void *get();
30 void push(void *obj);
31
32 /* Mem::Allocator API */
33 size_t getStats(Mem::PoolStats &) override;
34 void setChunkSize(size_t) override;
35 bool idleTrigger(int) const override;
36 void clean(time_t) override;
37
38 protected:
39 /* Mem::Allocator API */
40 void *allocate() override;
41 void deallocate(void *) override;
42
43 public:
44 size_t chunk_size;
45 int chunk_capacity;
46 int chunkCount;
47 void *freeCache;
48 MemChunk *nextFreeChunk;
49 MemChunk *Chunks;
50 Splay<MemChunk *> allChunks;
51 };
52
53 /// \ingroup MemPoolsAPI
54 class MemChunk
55 {
56 public:
57 MemChunk(MemPoolChunked *pool);
58 ~MemChunk();
59 void *freeList;
60 void *objCache;
61 int inuse_count;
62 MemChunk *nextFreeChunk;
63 MemChunk *next;
64 time_t lastref;
65 MemPoolChunked *pool;
66 };
67
68 #endif /* SQUID_SRC_MEM_POOLCHUNKED_H */
69