From owner-svn-src-all@freebsd.org Fri May 6 16:41:25 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 3DE9AB2F2C9; Fri, 6 May 2016 16:41:25 +0000 (UTC) (envelope-from royger@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 0CB01195D; Fri, 6 May 2016 16:41:24 +0000 (UTC) (envelope-from royger@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u46GfOWL026239; Fri, 6 May 2016 16:41:24 GMT (envelope-from royger@FreeBSD.org) Received: (from royger@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u46GfOY2026236; Fri, 6 May 2016 16:41:24 GMT (envelope-from royger@FreeBSD.org) Message-Id: <201605061641.u46GfOY2026236@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: royger set sender to royger@FreeBSD.org using -f From: =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= Date: Fri, 6 May 2016 16:41:24 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r299184 - head/sys/sys X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 06 May 2016 16:41:25 -0000 Author: royger Date: Fri May 6 16:41:23 2016 New Revision: 299184 URL: https://svnweb.freebsd.org/changeset/base/299184 Log: 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 Modified: head/sys/sys/_bitset.h head/sys/sys/bitset.h Modified: head/sys/sys/_bitset.h ============================================================================== --- head/sys/sys/_bitset.h Fri May 6 16:03:40 2016 (r299183) +++ head/sys/sys/_bitset.h Fri May 6 16:41:23 2016 (r299184) @@ -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_ */ Modified: head/sys/sys/bitset.h ============================================================================== --- head/sys/sys/bitset.h Fri May 6 16:03:40 2016 (r299183) +++ head/sys/sys/bitset.h Fri May 6 16:41:23 2016 (r299184) @@ -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_ */