summaryrefslogtreecommitdiff
path: root/usr/src/uts/common/os/group.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src/uts/common/os/group.c')
-rw-r--r--usr/src/uts/common/os/group.c37
1 files changed, 33 insertions, 4 deletions
diff --git a/usr/src/uts/common/os/group.c b/usr/src/uts/common/os/group.c
index b15dff181f..8c1bc7e491 100644
--- a/usr/src/uts/common/os/group.c
+++ b/usr/src/uts/common/os/group.c
@@ -19,12 +19,10 @@
* CDDL HEADER END
*/
/*
- * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#include <sys/systm.h>
#include <sys/param.h>
#include <sys/debug.h>
@@ -64,6 +62,21 @@ group_destroy(group_t *g)
}
/*
+ * Empty a group_t
+ * Capacity is preserved.
+ */
+void
+group_empty(group_t *g)
+{
+ int i;
+ int sz = g->grp_size;
+
+ g->grp_size = 0;
+ for (i = 0; i < sz; i++)
+ g->grp_set[i] = NULL;
+}
+
+/*
* Add element "e" to group "g"
*
* Returns -1 if addition would result in overcapacity, and
@@ -312,7 +325,7 @@ group_add_at(group_t *g, void *e, uint_t idx)
}
/*
- * Remove the entry at the specified index
+ * Remove the element at the specified index
*/
void
group_remove_at(group_t *g, uint_t idx)
@@ -320,3 +333,19 @@ group_remove_at(group_t *g, uint_t idx)
ASSERT(idx < g->grp_capacity);
g->grp_set[idx] = NULL;
}
+
+/*
+ * Find an element in the group, and return its index
+ * Returns -1 if the element could not be found.
+ */
+uint_t
+group_find(group_t *g, void *e)
+{
+ uint_t idx;
+
+ for (idx = 0; idx < g->grp_capacity; idx++) {
+ if (g->grp_set[idx] == e)
+ return (idx);
+ }
+ return ((uint_t)-1);
+}