bitset: introduce helpers to allocate a bitset at runtime

Introduce some new helpers to declare and allocate a dynamic bitset, whose
size is not a constant.

Sponsored by:		Citrix Systems R&D
Reviewed by:		kib jhb
Differential revision:	https://reviews.freebsd.org/D6226
This commit is contained in:
Roger Pau Monné 2016-05-06 16:41:23 +00:00
parent 89017bc259
commit 03f5b58d56
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=299184
2 changed files with 14 additions and 0 deletions

View File

@ -47,4 +47,12 @@ struct t { \
long __bits[__bitset_words((_s))]; \
}
/*
* Helper to declare a bitset without it's size being a constant.
*
* Sadly we cannot declare a bitset struct with '__bits[]', because it's
* the only member of the struct and the compiler complains.
*/
#define BITSET_DEFINE_VAR(t) BITSET_DEFINE(t, 1)
#endif /* !_SYS__BITSET_H_ */

View File

@ -199,4 +199,10 @@
#define BITSET_FSET(n) \
[ 0 ... ((n) - 1) ] = (-1L)
/*
* Dynamically allocate a bitset.
*/
#define BITSET_ALLOC(_s, mt, mf) \
malloc(__bitset_words(_s) * sizeof(long), mt, (mf))
#endif /* !_SYS_BITSET_H_ */