-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpool.h
More file actions
55 lines (46 loc) · 912 Bytes
/
pool.h
File metadata and controls
55 lines (46 loc) · 912 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <vector>
#include <stdlib.h>
#include <stdio.h>
struct Pool
{
std::vector<char> pool;
int lock;
};
class PoolView
{
public:
PoolView(Pool& pool, const char* name=""):
pool(pool),
name(name)
{
pool.lock++;
}
PoolView(const PoolView& other):PoolView(other.pool, other.name) {}
PoolView(PoolView&& other):PoolView(other.pool, other.name) {}
~PoolView()
{
pool.lock--;
if (*name != '\0')
{
printf("Relinquishing pool %s\n", name);
}
else
{
printf("Relinquishing pool at %p\n", this);
}
}
std::vector<char>& operator*()
{
return pool.pool;
}
std::vector<char>* operator->()
{
return &pool.pool;
}
Pool& pool;
const char* name;
std::vector<char>& vector() {return pool.pool;}
};
void add_pool_of_size(size_t size);
void init_pools(std::vector<size_t> sizes);
PoolView get_pool(size_t min_size);