summaryrefslogtreecommitdiffstats
path: root/sys/sys
diff options
context:
space:
mode:
authorroyger <royger@FreeBSD.org>2016-05-06 16:41:23 +0000
committerroyger <royger@FreeBSD.org>2016-05-06 16:41:23 +0000
commit4bf5db0a14f80296b60c436d2e67bbba00f74d01 (patch)
tree6c5c93b09ce2ee9eb0bb3fb9491f984dcb99d7a5 /sys/sys
parent0bb25b8d7b1f4524d2a9b3c950eedbafbbc63d0d (diff)
downloadFreeBSD-src-4bf5db0a14f80296b60c436d2e67bbba00f74d01.zip
FreeBSD-src-4bf5db0a14f80296b60c436d2e67bbba00f74d01.tar.gz
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
Diffstat (limited to 'sys/sys')
-rw-r--r--sys/sys/_bitset.h8
-rw-r--r--sys/sys/bitset.h6
2 files changed, 14 insertions, 0 deletions
diff --git a/sys/sys/_bitset.h b/sys/sys/_bitset.h
index 86cf539..2f5301d 100644
--- a/sys/sys/_bitset.h
+++ b/sys/sys/_bitset.h
@@ -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_ */
diff --git a/sys/sys/bitset.h b/sys/sys/bitset.h
index f1c7bf8..723c39b 100644
--- a/sys/sys/bitset.h
+++ b/sys/sys/bitset.h
@@ -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_ */
OpenPOWER on IntegriCloud