annotate dbmalloc.c @ 1385:6c92e97553f1 fuzz

Add a flag whether to longjmp, missed that last commit
author Matt Johnston <matt@ucc.asn.au>
date Thu, 01 Jun 2017 21:30:26 +0800
parents 7209a6e30932
children c42e8ff42bd1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1361
f9f930e1a516 add dbmalloc epoch cleanup
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1 #include "dbmalloc.h"
f9f930e1a516 add dbmalloc epoch cleanup
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
2 #include "dbutil.h"
f9f930e1a516 add dbmalloc epoch cleanup
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
3
f9f930e1a516 add dbmalloc epoch cleanup
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
4 struct dbmalloc_header {
f9f930e1a516 add dbmalloc epoch cleanup
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
5 unsigned int epoch;
1378
7209a6e30932 linked list dbmalloc now
Matt Johnston <matt@ucc.asn.au>
parents: 1365
diff changeset
6 struct dbmalloc_header *prev;
7209a6e30932 linked list dbmalloc now
Matt Johnston <matt@ucc.asn.au>
parents: 1365
diff changeset
7 struct dbmalloc_header *next;
1361
f9f930e1a516 add dbmalloc epoch cleanup
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
8 };
f9f930e1a516 add dbmalloc epoch cleanup
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
9
1378
7209a6e30932 linked list dbmalloc now
Matt Johnston <matt@ucc.asn.au>
parents: 1365
diff changeset
10 static void put_alloc(struct dbmalloc_header *header);
7209a6e30932 linked list dbmalloc now
Matt Johnston <matt@ucc.asn.au>
parents: 1365
diff changeset
11 static void remove_alloc(struct dbmalloc_header *header);
7209a6e30932 linked list dbmalloc now
Matt Johnston <matt@ucc.asn.au>
parents: 1365
diff changeset
12
7209a6e30932 linked list dbmalloc now
Matt Johnston <matt@ucc.asn.au>
parents: 1365
diff changeset
13 /* end of the linked list */
7209a6e30932 linked list dbmalloc now
Matt Johnston <matt@ucc.asn.au>
parents: 1365
diff changeset
14 static struct dbmalloc_header* staple;
1361
f9f930e1a516 add dbmalloc epoch cleanup
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
15
f9f930e1a516 add dbmalloc epoch cleanup
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
16 unsigned int current_epoch = 0;
f9f930e1a516 add dbmalloc epoch cleanup
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
17
f9f930e1a516 add dbmalloc epoch cleanup
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
18 void m_malloc_set_epoch(unsigned int epoch) {
f9f930e1a516 add dbmalloc epoch cleanup
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
19 current_epoch = epoch;
f9f930e1a516 add dbmalloc epoch cleanup
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
20 }
f9f930e1a516 add dbmalloc epoch cleanup
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
21
1378
7209a6e30932 linked list dbmalloc now
Matt Johnston <matt@ucc.asn.au>
parents: 1365
diff changeset
22 void m_malloc_free_epoch(unsigned int epoch, int dofree) {
7209a6e30932 linked list dbmalloc now
Matt Johnston <matt@ucc.asn.au>
parents: 1365
diff changeset
23 struct dbmalloc_header* header;
7209a6e30932 linked list dbmalloc now
Matt Johnston <matt@ucc.asn.au>
parents: 1365
diff changeset
24 struct dbmalloc_header* nextheader = NULL;
7209a6e30932 linked list dbmalloc now
Matt Johnston <matt@ucc.asn.au>
parents: 1365
diff changeset
25 struct dbmalloc_header* oldstaple = staple;
7209a6e30932 linked list dbmalloc now
Matt Johnston <matt@ucc.asn.au>
parents: 1365
diff changeset
26 staple = NULL;
7209a6e30932 linked list dbmalloc now
Matt Johnston <matt@ucc.asn.au>
parents: 1365
diff changeset
27 /* free allocations from this epoch, create a new staple-anchored list from
7209a6e30932 linked list dbmalloc now
Matt Johnston <matt@ucc.asn.au>
parents: 1365
diff changeset
28 the remainder */
7209a6e30932 linked list dbmalloc now
Matt Johnston <matt@ucc.asn.au>
parents: 1365
diff changeset
29 for (header = oldstaple; header; header = nextheader)
7209a6e30932 linked list dbmalloc now
Matt Johnston <matt@ucc.asn.au>
parents: 1365
diff changeset
30 {
7209a6e30932 linked list dbmalloc now
Matt Johnston <matt@ucc.asn.au>
parents: 1365
diff changeset
31 nextheader = header->next;
7209a6e30932 linked list dbmalloc now
Matt Johnston <matt@ucc.asn.au>
parents: 1365
diff changeset
32 if (header->epoch == epoch) {
7209a6e30932 linked list dbmalloc now
Matt Johnston <matt@ucc.asn.au>
parents: 1365
diff changeset
33 if (dofree) {
7209a6e30932 linked list dbmalloc now
Matt Johnston <matt@ucc.asn.au>
parents: 1365
diff changeset
34 free(header);
1361
f9f930e1a516 add dbmalloc epoch cleanup
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
35 }
1378
7209a6e30932 linked list dbmalloc now
Matt Johnston <matt@ucc.asn.au>
parents: 1365
diff changeset
36 } else {
7209a6e30932 linked list dbmalloc now
Matt Johnston <matt@ucc.asn.au>
parents: 1365
diff changeset