blob: 98de2c970c014badd30a3f8a6bbbcf6d1273cda7 [file] [log] [blame]
Abhishek Kumar9892dc82020-05-18 20:00:23 +05301#ifndef COMMIT_SLAB_DECL_H
2#define COMMIT_SLAB_DECL_H
Nguyễn Thái Ngọc Duya9f1f1f2018-05-19 07:28:17 +02003
4/* allocate ~512kB at once, allowing for malloc overhead */
5#ifndef COMMIT_SLAB_SIZE
6#define COMMIT_SLAB_SIZE (512*1024-32)
7#endif
8
9#define declare_commit_slab(slabname, elemtype) \
10 \
11struct slabname { \
12 unsigned slab_size; \
13 unsigned stride; \
14 unsigned slab_count; \
15 elemtype **slab; \
16}
17
18/*
19 * Statically initialize a commit slab named "var". Note that this
20 * evaluates "stride" multiple times! Example:
21 *
22 * struct indegree indegrees = COMMIT_SLAB_INIT(1, indegrees);
23 *
24 */
25#define COMMIT_SLAB_INIT(stride, var) { \
26 COMMIT_SLAB_SIZE / sizeof(**((var).slab)) / (stride), \
27 (stride), 0, NULL \
28}
29
Nguyễn Thái Ngọc Duy878f0bb2018-05-19 07:28:18 +020030#define declare_commit_slab_prototypes(slabname, elemtype) \
31 \
32void init_ ##slabname## _with_stride(struct slabname *s, unsigned stride); \
33void init_ ##slabname(struct slabname *s); \
34void clear_ ##slabname(struct slabname *s); \
SZEDER Gábor1df15f82020-06-05 13:00:26 +000035void deep_clear_ ##slabname(struct slabname *s, void (*free_fn)(elemtype *ptr)); \
Nguyễn Thái Ngọc Duy878f0bb2018-05-19 07:28:18 +020036elemtype *slabname## _at_peek(struct slabname *s, const struct commit *c, int add_if_missing); \
37elemtype *slabname## _at(struct slabname *s, const struct commit *c); \
38elemtype *slabname## _peek(struct slabname *s, const struct commit *c)
39
40#define define_shared_commit_slab(slabname, elemtype) \
41 declare_commit_slab(slabname, elemtype); \
42 declare_commit_slab_prototypes(slabname, elemtype)
43
Abhishek Kumar9892dc82020-05-18 20:00:23 +053044#endif /* COMMIT_SLAB_DECL_H */