Skip to content

Commit 878f0bb

Browse files
pcloudsgitster
authored andcommitted
commit-slab: support shared commit-slab
define_shared_commit_slab() could be used in a header file to define a commit-slab. One of these C files must include commit-slab-impl.h and "call" implement_shared_commit_slab(). Signed-off-by: Junio C Hamano <[email protected]>
1 parent a9f1f1f commit 878f0bb

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

commit-slab-decl.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,17 @@ struct slabname { \
2727
(stride), 0, NULL \
2828
}
2929

30+
#define declare_commit_slab_prototypes(slabname, elemtype) \
31+
\
32+
void init_ ##slabname## _with_stride(struct slabname *s, unsigned stride); \
33+
void init_ ##slabname(struct slabname *s); \
34+
void clear_ ##slabname(struct slabname *s); \
35+
elemtype *slabname## _at_peek(struct slabname *s, const struct commit *c, int add_if_missing); \
36+
elemtype *slabname## _at(struct slabname *s, const struct commit *c); \
37+
elemtype *slabname## _peek(struct slabname *s, const struct commit *c)
38+
39+
#define define_shared_commit_slab(slabname, elemtype) \
40+
declare_commit_slab(slabname, elemtype); \
41+
declare_commit_slab_prototypes(slabname, elemtype)
42+
3043
#endif /* COMMIT_SLAB_HDR_H */

commit-slab-impl.h

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@
33

44
#define MAYBE_UNUSED __attribute__((__unused__))
55

6-
#define implement_commit_slab(slabname, elemtype) \
6+
#define implement_static_commit_slab(slabname, elemtype) \
7+
implement_commit_slab(slabname, elemtype, static MAYBE_UNUSED)
8+
9+
#define implement_shared_commit_slab(slabname, elemtype) \
10+
implement_commit_slab(slabname, elemtype, )
11+
12+
#define implement_commit_slab(slabname, elemtype, scope) \
713
\
814
static int stat_ ##slabname## realloc; \
915
\
10-
static MAYBE_UNUSED void init_ ##slabname## _with_stride(struct slabname *s, \
16+
scope void init_ ##slabname## _with_stride(struct slabname *s, \
1117
unsigned stride) \
1218
{ \
1319
unsigned int elem_size; \
@@ -20,12 +26,12 @@ static MAYBE_UNUSED void init_ ##slabname## _with_stride(struct slabname *s, \
2026
s->slab = NULL; \
2127
} \
2228
\
23-
static MAYBE_UNUSED void init_ ##slabname(struct slabname *s) \
29+
scope void init_ ##slabname(struct slabname *s) \
2430
{ \
2531
init_ ##slabname## _with_stride(s, 1); \
2632
} \
2733
\
28-
static MAYBE_UNUSED void clear_ ##slabname(struct slabname *s) \
34+
scope void clear_ ##slabname(struct slabname *s) \
2935
{ \
3036
unsigned int i; \
3137
for (i = 0; i < s->slab_count; i++) \
@@ -34,7 +40,7 @@ static MAYBE_UNUSED void clear_ ##slabname(struct slabname *s) \
3440
FREE_AND_NULL(s->slab); \
3541
} \
3642
\
37-
static MAYBE_UNUSED elemtype *slabname## _at_peek(struct slabname *s, \
43+
scope elemtype *slabname## _at_peek(struct slabname *s, \
3844
const struct commit *c, \
3945
int add_if_missing) \
4046
{ \
@@ -62,13 +68,13 @@ static MAYBE_UNUSED elemtype *slabname## _at_peek(struct slabname *s, \
6268
return &s->slab[nth_slab][nth_slot * s->stride]; \
6369
} \
6470
\
65-
static MAYBE_UNUSED elemtype *slabname## _at(struct slabname *s, \
71+
scope elemtype *slabname## _at(struct slabname *s, \
6672
const struct commit *c) \
6773
{ \
6874
return slabname##_at_peek(s, c, 1); \
6975
} \
7076
\
71-
static MAYBE_UNUSED elemtype *slabname## _peek(struct slabname *s, \
77+
scope elemtype *slabname## _peek(struct slabname *s, \
7278
const struct commit *c) \
7379
{ \
7480
return slabname##_at_peek(s, c, 0); \
@@ -81,7 +87,7 @@ struct slabname
8187
* to allow a terminating semicolon, which makes instantiations look
8288
* like function declarations. I.e., the expansion of
8389
*
84-
* implement_commit_slab(indegree, int);
90+
* implement_commit_slab(indegree, int, static);
8591
*
8692
* ends in 'struct indegree;'. This would otherwise
8793
* be a syntax error according (at least) to ISO C. It's hard to

commit-slab.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@
4646

4747
#define define_commit_slab(slabname, elemtype) \
4848
declare_commit_slab(slabname, elemtype); \
49-
implement_commit_slab(slabname, elemtype)
49+
implement_static_commit_slab(slabname, elemtype)
5050

5151
#endif /* COMMIT_SLAB_H */

0 commit comments

Comments
 (0)