1361
|
1 #include "dbmalloc.h" |
|
2 #include "dbutil.h" |
|
3 |
|
4 struct dbmalloc_header { |
|
5 unsigned int epoch; |
1378
|
6 struct dbmalloc_header *prev; |
|
7 struct dbmalloc_header *next; |
1361
|
8 }; |
|
9 |
1378
|
10 static void put_alloc(struct dbmalloc_header *header); |
|
11 static void remove_alloc(struct dbmalloc_header *header); |
|
12 |
|
13 /* end of the linked list */ |
|
14 static struct dbmalloc_header* staple; |
1361
|
15 |
|
16 unsigned int current_epoch = 0; |
|
17 |
|
18 void m_malloc_set_epoch(unsigned int epoch) { |
|
19 current_epoch = epoch; |
|
20 } |
|
21 |
1378
|
22 void m_malloc_free_epoch(unsigned int epoch, int dofree) { |
|
23 struct dbmalloc_header* header; |
|
24 struct dbmalloc_header* nextheader = NULL; |
|
25 struct dbmalloc_header* oldstaple = staple; |
|
26 staple = NULL; |
|
27 /* free allocations from this epoch, create a new staple-anchored list from |
|
28 the remainder */ |
|
29 for (header = oldstaple; header; header = nextheader) |
|
30 { |
|
31 nextheader = header->next; |
|
32 if (header->epoch == epoch) { |
|
33 if (dofree) { |
|
34 free(header); |
1361
|
35 } |
1378
|
36 } else { |
|
|