xref: /onnv-gate/usr/src/uts/common/sys/bitset.h (revision 10696:cd0f390dd9e2)
13434Sesaxe /*
23434Sesaxe  * CDDL HEADER START
33434Sesaxe  *
43434Sesaxe  * The contents of this file are subject to the terms of the
53434Sesaxe  * Common Development and Distribution License (the "License").
63434Sesaxe  * You may not use this file except in compliance with the License.
73434Sesaxe  *
83434Sesaxe  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
93434Sesaxe  * or http://www.opensolaris.org/os/licensing.
103434Sesaxe  * See the License for the specific language governing permissions
113434Sesaxe  * and limitations under the License.
123434Sesaxe  *
133434Sesaxe  * When distributing Covered Code, include this CDDL HEADER in each
143434Sesaxe  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
153434Sesaxe  * If applicable, add the following below this CDDL HEADER, with the
163434Sesaxe  * fields enclosed by brackets "[]" replaced with your own identifying
173434Sesaxe  * information: Portions Copyright [yyyy] [name of copyright owner]
183434Sesaxe  *
193434Sesaxe  * CDDL HEADER END
203434Sesaxe  */
213434Sesaxe /*
22*10696SDavid.Hollister@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
233434Sesaxe  * Use is subject to license terms.
243434Sesaxe  */
253434Sesaxe 
263434Sesaxe #ifndef	_BITSET_H
273434Sesaxe #define	_BITSET_H
283434Sesaxe 
293434Sesaxe #ifdef	__cplusplus
303434Sesaxe extern "C" {
313434Sesaxe #endif
323434Sesaxe 
333434Sesaxe #if (defined(_KERNEL) || defined(_KMEMUSER))
343434Sesaxe #include <sys/bitmap.h>
353434Sesaxe #include <sys/types.h>
363434Sesaxe 
373434Sesaxe typedef struct bitset {
383434Sesaxe 	ulong_t	*bs_set;
393434Sesaxe 	uint_t	bs_words;
403434Sesaxe } bitset_t;
413434Sesaxe 
423434Sesaxe /*
433434Sesaxe  * Bitset initialiation / teardown
443434Sesaxe  */
453434Sesaxe void		bitset_init(bitset_t *);
463434Sesaxe void		bitset_fini(bitset_t *);
473434Sesaxe 
483434Sesaxe /*
493434Sesaxe  * Resize / query a bitset's holding capacity
503434Sesaxe  */
513434Sesaxe void		bitset_resize(bitset_t *, uint_t);
523434Sesaxe uint_t		bitset_capacity(bitset_t *);
533434Sesaxe 
543434Sesaxe /*
553434Sesaxe  * Set / clear a bit in the set
563434Sesaxe  */
573434Sesaxe void		bitset_add(bitset_t *, uint_t);
583434Sesaxe void		bitset_del(bitset_t *, uint_t);
593434Sesaxe 
603434Sesaxe /*
618408SEric.Saxe@Sun.COM  * Atomic operations
628408SEric.Saxe@Sun.COM  */
638408SEric.Saxe@Sun.COM void		bitset_atomic_add(bitset_t *, uint_t);
648408SEric.Saxe@Sun.COM void		bitset_atomic_del(bitset_t *, uint_t);
658408SEric.Saxe@Sun.COM int		bitset_atomic_test_and_add(bitset_t *, uint_t);
668408SEric.Saxe@Sun.COM int		bitset_atomic_test_and_del(bitset_t *, uint_t);
678408SEric.Saxe@Sun.COM 
688408SEric.Saxe@Sun.COM /*
693434Sesaxe  * Bitset queries
703434Sesaxe  */
713434Sesaxe int		bitset_in_set(bitset_t *, uint_t);
723434Sesaxe int		bitset_is_null(bitset_t *);
733434Sesaxe uint_t		bitset_find(bitset_t *);
743434Sesaxe 
75*10696SDavid.Hollister@Sun.COM /*
76*10696SDavid.Hollister@Sun.COM  * Bitset computations
77*10696SDavid.Hollister@Sun.COM  */
78*10696SDavid.Hollister@Sun.COM int		bitset_and(bitset_t *, bitset_t *, bitset_t *);
79*10696SDavid.Hollister@Sun.COM int		bitset_or(bitset_t *, bitset_t *, bitset_t *);
80*10696SDavid.Hollister@Sun.COM int		bitset_xor(bitset_t *, bitset_t *, bitset_t *);
81*10696SDavid.Hollister@Sun.COM 
82*10696SDavid.Hollister@Sun.COM /*
83*10696SDavid.Hollister@Sun.COM  * Miscellaneous bitset operations
84*10696SDavid.Hollister@Sun.COM  */
85*10696SDavid.Hollister@Sun.COM void		bitset_zero(bitset_t *);
86*10696SDavid.Hollister@Sun.COM void		bitset_copy(bitset_t *, bitset_t *);
87*10696SDavid.Hollister@Sun.COM int		bitset_match(bitset_t *, bitset_t *);
88*10696SDavid.Hollister@Sun.COM 
893434Sesaxe #endif	/* !_KERNEL && !_KMEMUSER */
903434Sesaxe 
913434Sesaxe #ifdef	__cplusplus
923434Sesaxe }
933434Sesaxe #endif
943434Sesaxe 
953434Sesaxe #endif /* _BITSET_H */
96