commit-slab.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #ifndef COMMIT_SLAB_H
  2. #define COMMIT_SLAB_H
  3. #include "commit-slab-decl.h"
  4. #include "commit-slab-impl.h"
  5. /*
  6. * define_commit_slab(slabname, elemtype) creates boilerplate code to define
  7. * a new struct (struct slabname) that is used to associate a piece of data
  8. * of elemtype to commits, and a few functions to use that struct.
  9. *
  10. * After including this header file, using:
  11. *
  12. * define_commit_slab(indegree, int);
  13. *
  14. * will let you call the following functions:
  15. *
  16. * - int *indegree_at(struct indegree *, struct commit *);
  17. *
  18. * This function locates the data associated with the given commit in
  19. * the indegree slab, and returns the pointer to it. The location to
  20. * store the data is allocated as necessary.
  21. *
  22. * - int *indegree_peek(struct indegree *, struct commit *);
  23. *
  24. * This function is similar to indegree_at(), but it will return NULL
  25. * if the location to store the data associated with the given commit
  26. * has not been allocated yet.
  27. * Note that the location to store the data might have already been
  28. * allocated even if no indegree_at() call has been made for that commit
  29. * yet; in this case this function returns a pointer to a
  30. * zero-initialized location.
  31. *
  32. * - void init_indegree(struct indegree *);
  33. * void init_indegree_with_stride(struct indegree *, int);
  34. *
  35. * Initializes the indegree slab that associates an array of integers
  36. * to each commit. 'stride' specifies how big each array is. The slab
  37. * that is initialized by the variant without "_with_stride" associates
  38. * each commit with an array of one integer.
  39. *
  40. * - void clear_indegree(struct indegree *);
  41. *
  42. * Empties the slab. The slab can be reused with the same stride
  43. * without calling init_indegree() again or can be reconfigured to a
  44. * different stride by calling init_indegree_with_stride().
  45. *
  46. * Call this function before the slab falls out of scope to avoid
  47. * leaking memory.
  48. *
  49. * - void deep_clear_indegree(struct indegree *, void (*free_fn)(int*))
  50. *
  51. * Empties the slab, similar to clear_indegree(), but in addition it
  52. * calls the given 'free_fn' for each slab entry to release any
  53. * additional memory that might be owned by the entry (but not the
  54. * entry itself!).
  55. * Note that 'free_fn' might be called even for entries for which no
  56. * indegree_at() call has been made; in this case 'free_fn' is invoked
  57. * with a pointer to a zero-initialized location.
  58. */
  59. #define define_commit_slab(slabname, elemtype) \
  60. declare_commit_slab(slabname, elemtype); \
  61. implement_static_commit_slab(slabname, elemtype)
  62. #endif /* COMMIT_SLAB_H */