From: Jeff King Date: Tue, 10 Jun 2014 21:42:51 +0000 (-0400) Subject: commit-slab: provide a static initializer X-Git-Tag: v2.0.2~4^2~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=80cdaba569600154d91819d2e252f6b7dd9cff73;p=git 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 Signed-off-by: Junio C Hamano --- diff --git a/commit-slab.h b/commit-slab.h index cc114b53b0..375c9c751a 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 */