]> jfr.im git - irc/quakenet/newserv.git/blame_incremental - core/nsmalloc.h
merge
[irc/quakenet/newserv.git] / core / nsmalloc.h
... / ...
CommitLineData
1/* nsmalloc: Simple pooled malloc() thing. */
2
3#ifndef __NSMALLOC_H
4#define __NSMALLOC_H
5
6#ifdef __NSMALLOC_C
7#define pool(x) #x
8#define beginpools() char *nsmpoolnames[MAXPOOL] =
9#define endpools();
10#else
11#define pool(x) POOL_ ## x
12#define beginpools(x) typedef enum nsmallocpools
13#define endpools() nsmallocpools; extern char *nsmpoolnames[MAXPOOL];
14
15#include <stdlib.h>
16#include <stdint.h>
17
18void *nsmalloc(unsigned int poolid, size_t size);
19void nsfree(unsigned int poolid, void *ptr);
20void nsfreeall(unsigned int poolid);
21void nsinit(void);
22void nsexit(void);
23void *nsrealloc(unsigned int poolid, void *ptr, size_t size);
24void nscheckfreeall(unsigned int poolid);
25void *nscalloc(unsigned int poolid, size_t nmemb, size_t size);
26
27#define MAXPOOL 100
28#define REDZONE_MAGIC 0x243653E957851F68ULL
29struct nsminfo {
30 struct nsminfo *next;
31 struct nsminfo *prev;
32
33 size_t size;
34 uint64_t redzone;
35 char data[];
36};
37
38struct nsmpool {
39 unsigned long count;
40 size_t size;
41 struct nsminfo *blocks;
42};
43
44extern struct nsmpool nsmpools[MAXPOOL];
45
46#endif
47
48/* Pools here in the order they were created */
49
50beginpools() {
51 pool(AUTHEXT),
52 pool(CHANINDEX),
53 pool(BANS),
54 pool(CHANNEL),
55 pool(NICK),
56 pool(CHANSERVDB),
57 pool(SSTRING),
58 pool(AUTHTRACKER),
59 pool(PROXYSCAN),
60 pool(LUA),
61 pool(TROJANSCAN),
62 pool(NTERFACER),
63 pool(SQLITE),
64 pool(PQSQL),
65 pool(PATRICIA),
66 pool(PATRICIANICK),
67 pool(GLINE),
68 pool(TRUSTS),
69 pool(SPAMSCAN2),
70 pool(ACHIEVEMENTS),
71 pool(CHANSTATS),
72 pool(SCHEDULE)
73} endpools()
74
75#undef pool
76#undef beginpools
77#undef endpools
78
79#endif