Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 80cdaba

Browse files
peffgitster
authored andcommitted
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>
1 parent bc6b8fc commit 80cdaba

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

commit-slab.h

+12
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,16 @@ static int stat_ ##slabname## realloc
117117
* catch because GCC silently parses it by default.
118118
*/
119119

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+
120132
#endif /* COMMIT_SLAB_H */

0 commit comments

Comments
 (0)