xref: /titanic_44/usr/src/uts/common/sys/bitset.h (revision 4c06356b0f0fffb4fc1b6eccc8e5d8e2254a84d6)
1fb2f18f8Sesaxe /*
2fb2f18f8Sesaxe  * CDDL HEADER START
3fb2f18f8Sesaxe  *
4fb2f18f8Sesaxe  * The contents of this file are subject to the terms of the
5fb2f18f8Sesaxe  * Common Development and Distribution License (the "License").
6fb2f18f8Sesaxe  * You may not use this file except in compliance with the License.
7fb2f18f8Sesaxe  *
8fb2f18f8Sesaxe  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fb2f18f8Sesaxe  * or http://www.opensolaris.org/os/licensing.
10fb2f18f8Sesaxe  * See the License for the specific language governing permissions
11fb2f18f8Sesaxe  * and limitations under the License.
12fb2f18f8Sesaxe  *
13fb2f18f8Sesaxe  * When distributing Covered Code, include this CDDL HEADER in each
14fb2f18f8Sesaxe  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fb2f18f8Sesaxe  * If applicable, add the following below this CDDL HEADER, with the
16fb2f18f8Sesaxe  * fields enclosed by brackets "[]" replaced with your own identifying
17fb2f18f8Sesaxe  * information: Portions Copyright [yyyy] [name of copyright owner]
18fb2f18f8Sesaxe  *
19fb2f18f8Sesaxe  * CDDL HEADER END
20fb2f18f8Sesaxe  */
21fb2f18f8Sesaxe /*
22*4c06356bSdh142964  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23fb2f18f8Sesaxe  * Use is subject to license terms.
24fb2f18f8Sesaxe  */
25fb2f18f8Sesaxe 
26fb2f18f8Sesaxe #ifndef	_BITSET_H
27fb2f18f8Sesaxe #define	_BITSET_H
28fb2f18f8Sesaxe 
29fb2f18f8Sesaxe #ifdef	__cplusplus
30fb2f18f8Sesaxe extern "C" {
31fb2f18f8Sesaxe #endif
32fb2f18f8Sesaxe 
33fb2f18f8Sesaxe #if (defined(_KERNEL) || defined(_KMEMUSER))
34fb2f18f8Sesaxe #include <sys/bitmap.h>
35fb2f18f8Sesaxe #include <sys/types.h>
36fb2f18f8Sesaxe 
37fb2f18f8Sesaxe typedef struct bitset {
38fb2f18f8Sesaxe 	ulong_t	*bs_set;
39fb2f18f8Sesaxe 	uint_t	bs_words;
40fb2f18f8Sesaxe } bitset_t;
41fb2f18f8Sesaxe 
42fb2f18f8Sesaxe /*
43fb2f18f8Sesaxe  * Bitset initialiation / teardown
44fb2f18f8Sesaxe  */
45fb2f18f8Sesaxe void		bitset_init(bitset_t *);
46fb2f18f8Sesaxe void		bitset_fini(bitset_t *);
47fb2f18f8Sesaxe 
48fb2f18f8Sesaxe /*
49fb2f18f8Sesaxe  * Resize / query a bitset's holding capacity
50fb2f18f8Sesaxe  */
51fb2f18f8Sesaxe void		bitset_resize(bitset_t *, uint_t);
52fb2f18f8Sesaxe uint_t		bitset_capacity(bitset_t *);
53fb2f18f8Sesaxe 
54fb2f18f8Sesaxe /*
55fb2f18f8Sesaxe  * Set / clear a bit in the set
56fb2f18f8Sesaxe  */
57fb2f18f8Sesaxe void		bitset_add(bitset_t *, uint_t);
58fb2f18f8Sesaxe void		bitset_del(bitset_t *, uint_t);
59fb2f18f8Sesaxe 
60fb2f18f8Sesaxe /*
616890d023SEric Saxe  * Atomic operations
626890d023SEric Saxe  */
636890d023SEric Saxe void		bitset_atomic_add(bitset_t *, uint_t);
646890d023SEric Saxe void		bitset_atomic_del(bitset_t *, uint_t);
656890d023SEric Saxe int		bitset_atomic_test_and_add(bitset_t *, uint_t);
666890d023SEric Saxe int		bitset_atomic_test_and_del(bitset_t *, uint_t);
676890d023SEric Saxe 
686890d023SEric Saxe /*
69fb2f18f8Sesaxe  * Bitset queries
70fb2f18f8Sesaxe  */
71fb2f18f8Sesaxe int		bitset_in_set(bitset_t *, uint_t);
72fb2f18f8Sesaxe int		bitset_is_null(bitset_t *);
73fb2f18f8Sesaxe uint_t		bitset_find(bitset_t *);
74fb2f18f8Sesaxe 
75*4c06356bSdh142964 /*
76*4c06356bSdh142964  * Bitset computations
77*4c06356bSdh142964  */
78*4c06356bSdh142964 int		bitset_and(bitset_t *, bitset_t *, bitset_t *);
79*4c06356bSdh142964 int		bitset_or(bitset_t *, bitset_t *, bitset_t *);
80*4c06356bSdh142964 int		bitset_xor(bitset_t *, bitset_t *, bitset_t *);
81*4c06356bSdh142964 
82*4c06356bSdh142964 /*
83*4c06356bSdh142964  * Miscellaneous bitset operations
84*4c06356bSdh142964  */
85*4c06356bSdh142964 void		bitset_zero(bitset_t *);
86*4c06356bSdh142964 void		bitset_copy(bitset_t *, bitset_t *);
87*4c06356bSdh142964 int		bitset_match(bitset_t *, bitset_t *);
88*4c06356bSdh142964 
89fb2f18f8Sesaxe #endif	/* !_KERNEL && !_KMEMUSER */
90fb2f18f8Sesaxe 
91fb2f18f8Sesaxe #ifdef	__cplusplus
92fb2f18f8Sesaxe }
93fb2f18f8Sesaxe #endif
94fb2f18f8Sesaxe 
95fb2f18f8Sesaxe #endif /* _BITSET_H */
96