grep: replace grep_read_mutex by internal obj read lock
[git.git] / commit-slab-decl.h
blobadc7b46c83b15f50ae2a85ce7e109fae4178f5fa
1 #ifndef COMMIT_SLAB_HDR_H
2 #define COMMIT_SLAB_HDR_H
4 /* allocate ~512kB at once, allowing for malloc overhead */
5 #ifndef COMMIT_SLAB_SIZE
6 #define COMMIT_SLAB_SIZE (512*1024-32)
7 #endif
9 #define declare_commit_slab(slabname, elemtype) \
11 struct slabname { \
12 unsigned slab_size; \
13 unsigned stride; \
14 unsigned slab_count; \
15 elemtype **slab; \
19 * Statically initialize a commit slab named "var". Note that this
20 * evaluates "stride" multiple times! Example:
22 * struct indegree indegrees = COMMIT_SLAB_INIT(1, indegrees);
25 #define COMMIT_SLAB_INIT(stride, var) { \
26 COMMIT_SLAB_SIZE / sizeof(**((var).slab)) / (stride), \
27 (stride), 0, NULL \
30 #define declare_commit_slab_prototypes(slabname, elemtype) \
32 void init_ ##slabname## _with_stride(struct slabname *s, unsigned stride); \
33 void init_ ##slabname(struct slabname *s); \
34 void clear_ ##slabname(struct slabname *s); \
35 elemtype *slabname## _at_peek(struct slabname *s, const struct commit *c, int add_if_missing); \
36 elemtype *slabname## _at(struct slabname *s, const struct commit *c); \
37 elemtype *slabname## _peek(struct slabname *s, const struct commit *c)
39 #define define_shared_commit_slab(slabname, elemtype) \
40 declare_commit_slab(slabname, elemtype); \
41 declare_commit_slab_prototypes(slabname, elemtype)
43 #endif /* COMMIT_SLAB_HDR_H */