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>
Jeff King committed
Jun 10, 2014 at 17:42 UTC
80cdaba569600154d91819d2e252f6b7dd9cff73
1 file changed
+12
commit-slab.h
+12
@@ -117,4 +117,16 @@ static int stat_ ##slabname## realloc
117
* catch because GCC silently parses it by default.
118
*/
119
120
+/*
121
+ * Statically initialize a commit slab named "var". Note that this
122
+ * evaluates "stride" multiple times! Example:
123
+ *
124
+ * struct indegree indegrees = COMMIT_SLAB_INIT(1, indegrees);
125
+ *
126
+ */
127
+#define COMMIT_SLAB_INIT(stride, var) { \
128
+ COMMIT_SLAB_SIZE / sizeof(**((var).slab)) / (stride), \
129
+ (stride), 0, NULL \
130
+}
131
+
132
#endif /* COMMIT_SLAB_H */