Skip to content

Commit 42359f1

Browse files
author
Kent Overstreet
committed
bcachefs: CLASS(darray)
Signed-off-by: Kent Overstreet <[email protected]>
1 parent 237a8e1 commit 42359f1

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

fs/bcachefs/darray.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* Inspired by CCAN's darray
99
*/
1010

11+
#include <linux/cleanup.h>
1112
#include <linux/slab.h>
1213

1314
#define DARRAY_PREALLOCATED(_type, _nr) \
@@ -112,6 +113,8 @@ int __bch2_darray_resize_noprof(darray_char *, size_t, size_t, gfp_t);
112113
#define darray_for_each_reverse(_d, _i) \
113114
for (typeof(&(_d).data[0]) _i = (_d).data + (_d).nr - 1; _i >= (_d).data && (_d).nr; --_i)
114115

116+
/* Init/exit */
117+
115118
#define darray_init(_d) \
116119
do { \
117120
(_d)->nr = 0; \
@@ -127,4 +130,29 @@ do { \
127130
darray_init(_d); \
128131
} while (0)
129132

133+
#define DEFINE_DARRAY_CLASS(_type) \
134+
DEFINE_CLASS(_type, _type, darray_exit(&(_T)), (_type) {}, void)
135+
136+
#define DEFINE_DARRAY(_type) \
137+
typedef DARRAY(_type) darray_##_type; \
138+
DEFINE_DARRAY_CLASS(darray_##_type)
139+
140+
#define DEFINE_DARRAY_NAMED(_name, _type) \
141+
typedef DARRAY(_type) _name; \
142+
DEFINE_DARRAY_CLASS(_name)
143+
144+
DEFINE_DARRAY_CLASS(darray_char);
145+
DEFINE_DARRAY_CLASS(darray_str)
146+
DEFINE_DARRAY_CLASS(darray_const_str)
147+
148+
DEFINE_DARRAY_CLASS(darray_u8)
149+
DEFINE_DARRAY_CLASS(darray_u16)
150+
DEFINE_DARRAY_CLASS(darray_u32)
151+
DEFINE_DARRAY_CLASS(darray_u64)
152+
153+
DEFINE_DARRAY_CLASS(darray_s8)
154+
DEFINE_DARRAY_CLASS(darray_s16)
155+
DEFINE_DARRAY_CLASS(darray_s32)
156+
DEFINE_DARRAY_CLASS(darray_s64)
157+
130158
#endif /* _BCACHEFS_DARRAY_H */

0 commit comments

Comments
 (0)