summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorTed Unangst <tedu@cvs.openbsd.org>2016-09-24 18:35:53 +0000
committerTed Unangst <tedu@cvs.openbsd.org>2016-09-24 18:35:53 +0000
commitd3bb61a47f64ece4fd39a052e1cc006d51b31149 (patch)
treed064db5a417324ec8b58195de8f4e358681c2616 /sys
parent5809de6815f215e331bcdb2a7dc104ea093df7d2 (diff)
introduce hashfree() function to free hash tables, with sizes.
ok guenther
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/kern_subr.c16
-rw-r--r--sys/sys/systm.h3
2 files changed, 17 insertions, 2 deletions
diff --git a/sys/kern/kern_subr.c b/sys/kern/kern_subr.c
index 1b91e391c8e..2653ec18ac4 100644
--- a/sys/kern/kern_subr.c
+++ b/sys/kern/kern_subr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_subr.c,v 1.47 2016/03/15 04:19:26 stefan Exp $ */
+/* $OpenBSD: kern_subr.c,v 1.48 2016/09/24 18:35:52 tedu Exp $ */
/* $NetBSD: kern_subr.c,v 1.15 1996/04/09 17:21:56 ragge Exp $ */
/*
@@ -176,6 +176,20 @@ hashinit(int elements, int type, int flags, u_long *hashmask)
return (hashtbl);
}
+void
+hashfree(void *hash, int elements, int type)
+{
+ u_long hashsize;
+ LIST_HEAD(generic, generic) *hashtbl = hash;
+
+ if (elements <= 0)
+ panic("hashfree: bad cnt");
+ for (hashsize = 1; hashsize < elements; hashsize <<= 1)
+ continue;
+
+ free(hashtbl, type, sizeof(*hashtbl) * hashsize);
+}
+
/*
* "startup hook" types, functions, and variables.
*/
diff --git a/sys/sys/systm.h b/sys/sys/systm.h
index b68b6a85521..5ef388b28b3 100644
--- a/sys/sys/systm.h
+++ b/sys/sys/systm.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: systm.h,v 1.118 2016/09/17 14:56:12 jasper Exp $ */
+/* $OpenBSD: systm.h,v 1.119 2016/09/24 18:35:52 tedu Exp $ */
/* $NetBSD: systm.h,v 1.50 1996/06/09 04:55:09 briggs Exp $ */
/*-
@@ -150,6 +150,7 @@ void vfs_op_init(void);
int seltrue(dev_t dev, int which, struct proc *);
int selfalse(dev_t dev, int which, struct proc *);
void *hashinit(int, int, int, u_long *);
+void hashfree(void *, int, int);
int sys_nosys(struct proc *, void *, register_t *);
void panic(const char *, ...)