]> jfr.im git - irc/quakenet/newserv.git/blame - core/nsmalloc.h
Use nsmalloc/nsfree for core/schedule.
[irc/quakenet/newserv.git] / core / nsmalloc.h
CommitLineData
34da4416 1/* nsmalloc: Simple pooled malloc() thing. */
2
271ef2d2
CP
3#ifndef __NSMALLOC_H
4#define __NSMALLOC_H
5
6#ifdef __NSMALLOC_C
7#define pool(x) #x
ed24756c 8#define beginpools() char *nsmpoolnames[MAXPOOL] =
271ef2d2
CP
9#define endpools();
10#else
11#define pool(x) POOL_ ## x
64e3058f 12#define beginpools(x) typedef enum nsmallocpools
ed24756c 13#define endpools() nsmallocpools; extern char *nsmpoolnames[MAXPOOL];
271ef2d2 14
34da4416 15#include <stdlib.h>
b19d9f45 16#include <stdint.h>
34da4416 17
18void *nsmalloc(unsigned int poolid, size_t size);
19void nsfree(unsigned int poolid, void *ptr);
20void nsfreeall(unsigned int poolid);
bf7e91f1 21void nsinit(void);
103521a1 22void nsexit(void);
48005496 23void *nsrealloc(unsigned int poolid, void *ptr, size_t size);
f8d5cfcf 24void nscheckfreeall(unsigned int poolid);
f358bcd6 25void *nscalloc(unsigned int poolid, size_t nmemb, size_t size);
34da4416 26
27#define MAXPOOL 100
b19d9f45 28#define REDZONE_MAGIC 0x243653E957851F68ULL
ed24756c
CP
29struct nsminfo {
30 struct nsminfo *next;
31 struct nsminfo *prev;
32
33 size_t size;
b19d9f45 34 uint64_t redzone;
ed24756c
CP
35 char data[];
36};
37
38struct nsmpool {
ed24756c
CP
39 unsigned long count;
40 size_t size;
bf7e91f1 41 struct nsminfo *blocks;
ed24756c
CP
42};
43
44extern struct nsmpool nsmpools[MAXPOOL];
45
271ef2d2
CP
46#endif
47
34da4416 48/* Pools here in the order they were created */
271ef2d2
CP
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),
76c8da69
CP
63 pool(SQLITE),
64 pool(PQSQL),
024c3d57 65 pool(PATRICIA),
84ca44e7 66 pool(PATRICIANICK),
7be67351
P
67 pool(GLINE),
68 pool(TRUSTS),
a85729f7 69 pool(SPAMSCAN2),
e5c21551 70 pool(ACHIEVEMENTS),
bbed4ab7
GB
71 pool(CHANSTATS),
72 pool(SCHEDULE)
271ef2d2
CP
73} endpools()
74
75#undef pool
76#undef beginpools
77#undef endpools
78
79#endif