summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2014-06-10 21:42:51 (GMT)
committerJunio C Hamano <gitster@pobox.com>2014-06-13 19:08:17 (GMT)
commit80cdaba569600154d91819d2e252f6b7dd9cff73 (patch)
tree73779fbdcd2c66ac0fde31efc93f772a127c7d1a
parentbc6b8fc1300ef79c4b4c3c2a79bb3c1e2e032963 (diff)
downloadgit-80cdaba569600154d91819d2e252f6b7dd9cff73.zip
git-80cdaba569600154d91819d2e252f6b7dd9cff73.tar.gz
git-80cdaba569600154d91819d2e252f6b7dd9cff73.tar.bz2
commit-slab: provide a static initializer
Callers currently must use init_foo_slab() at runtime before accessing a slab. For global slabs, it's much nicer if we can initialize them in BSS, so that each user does not have to add code to check-and-initialize. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--commit-slab.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/commit-slab.h b/commit-slab.h
index cc114b5..375c9c7 100644
--- a/commit-slab.h
+++ b/commit-slab.h
@@ -117,4 +117,16 @@ static int stat_ ##slabname## realloc
* catch because GCC silently parses it by default.
*/
+/*
+ * Statically initialize a commit slab named "var". Note that this
+ * evaluates "stride" multiple times! Example:
+ *
+ * struct indegree indegrees = COMMIT_SLAB_INIT(1, indegrees);
+ *
+ */
+#define COMMIT_SLAB_INIT(stride, var) { \
+ COMMIT_SLAB_SIZE / sizeof(**((var).slab)) / (stride), \
+ (stride), 0, NULL \
+}
+
#endif /* COMMIT_SLAB_H */