commit-slab-decl.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #ifndef COMMIT_SLAB_DECL_H
  2. #define COMMIT_SLAB_DECL_H
  3. /* allocate ~512kB at once, allowing for malloc overhead */
  4. #ifndef COMMIT_SLAB_SIZE
  5. #define COMMIT_SLAB_SIZE (512*1024-32)
  6. #endif
  7. #define declare_commit_slab(slabname, elemtype) \
  8. \
  9. struct slabname { \
  10. unsigned slab_size; \
  11. unsigned stride; \
  12. unsigned slab_count; \
  13. elemtype **slab; \
  14. }
  15. /*
  16. * Statically initialize a commit slab named "var". Note that this
  17. * evaluates "stride" multiple times! Example:
  18. *
  19. * struct indegree indegrees = COMMIT_SLAB_INIT(1, indegrees);
  20. *
  21. */
  22. #define COMMIT_SLAB_INIT(stride, var) { \
  23. COMMIT_SLAB_SIZE / sizeof(**((var).slab)) / (stride), \
  24. (stride), 0, NULL \
  25. }
  26. #define declare_commit_slab_prototypes(slabname, elemtype) \
  27. \
  28. void init_ ##slabname## _with_stride(struct slabname *s, unsigned stride); \
  29. void init_ ##slabname(struct slabname *s); \
  30. void clear_ ##slabname(struct slabname *s); \
  31. void deep_clear_ ##slabname(struct slabname *s, void (*free_fn)(elemtype *ptr)); \
  32. elemtype *slabname## _at_peek(struct slabname *s, const struct commit *c, int add_if_missing); \
  33. elemtype *slabname## _at(struct slabname *s, const struct commit *c); \
  34. elemtype *slabname## _peek(struct slabname *s, const struct commit *c)
  35. #define define_shared_commit_slab(slabname, elemtype) \
  36. declare_commit_slab(slabname, elemtype); \
  37. declare_commit_slab_prototypes(slabname, elemtype)
  38. #endif /* COMMIT_SLAB_DECL_H */