6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26 #include <sys/systm.h>
27 #include <sys/param.h>
28 #include <sys/debug.h>
29 #include <sys/kmem.h>
30 #include <sys/group.h>
31 #include <sys/cmn_err.h>
32
33
34 #define GRP_SET_SIZE_DEFAULT 2
35
36 static void group_grow_set(group_t *);
37 static void group_shrink_set(group_t *);
38 static void group_pack_set(void **, uint_t);
39
40 /*
41 * Initialize a group_t
42 */
43 void
44 group_create(group_t *g)
45 {
114 {
115 int i;
116
117 if (g->grp_size == 0)
118 return (-1);
119
120 /*
121 * Find the element in the group's set
122 */
123 for (i = 0; i < g->grp_size; i++)
124 if (g->grp_set[i] == e)
125 break;
126 if (g->grp_set[i] != e)
127 return (-1);
128
129 g->grp_set[i] = NULL;
130 group_pack_set(g->grp_set, g->grp_size);
131 g->grp_size--;
132
133 if ((gflag & GRP_RESIZE) &&
134 g->grp_size > GRP_SET_SIZE_DEFAULT &&
135 ((g->grp_size - 1) & g->grp_size) == 0)
136 group_shrink_set(g);
137
138 return (0);
139 }
140
141 /*
142 * Expand the capacity of group "g" so that it may
143 * contain at least "n" elements
144 */
145 void
146 group_expand(group_t *g, uint_t n)
147 {
148 while (g->grp_capacity < n)
149 group_grow_set(g);
150 }
151
152 /*
153 * Upsize a group's holding capacity
154 */
155 static void
|
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26 #include <sys/sysmacros.h>
27 #include <sys/systm.h>
28 #include <sys/param.h>
29 #include <sys/debug.h>
30 #include <sys/kmem.h>
31 #include <sys/group.h>
32 #include <sys/cmn_err.h>
33
34
35 #define GRP_SET_SIZE_DEFAULT 2
36
37 static void group_grow_set(group_t *);
38 static void group_shrink_set(group_t *);
39 static void group_pack_set(void **, uint_t);
40
41 /*
42 * Initialize a group_t
43 */
44 void
45 group_create(group_t *g)
46 {
115 {
116 int i;
117
118 if (g->grp_size == 0)
119 return (-1);
120
121 /*
122 * Find the element in the group's set
123 */
124 for (i = 0; i < g->grp_size; i++)
125 if (g->grp_set[i] == e)
126 break;
127 if (g->grp_set[i] != e)
128 return (-1);
129
130 g->grp_set[i] = NULL;
131 group_pack_set(g->grp_set, g->grp_size);
132 g->grp_size--;
133
134 if ((gflag & GRP_RESIZE) &&
135 g->grp_size > GRP_SET_SIZE_DEFAULT && ISP2(g->grp_size))
136 group_shrink_set(g);
137
138 return (0);
139 }
140
141 /*
142 * Expand the capacity of group "g" so that it may
143 * contain at least "n" elements
144 */
145 void
146 group_expand(group_t *g, uint_t n)
147 {
148 while (g->grp_capacity < n)
149 group_grow_set(g);
150 }
151
152 /*
153 * Upsize a group's holding capacity
154 */
155 static void
|