Skip to content

Commit

Permalink
commit-slab: provide a static initializer
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Jun 13, 2014
1 parent bc6b8fc commit 80cdaba
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions commit-slab.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

0 comments on commit 80cdaba

Please sign in to comment.