summaryrefslogtreecommitdiff
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
parent5809de6815f215e331bcdb2a7dc104ea093df7d2 (diff)
introduce hashfree() function to free hash tables, with sizes.
ok guenther
-rw-r--r--share/man/man9/hashinit.911
-rw-r--r--sys/kern/kern_subr.c16
-rw-r--r--sys/sys/systm.h3
3 files changed, 23 insertions, 7 deletions
diff --git a/share/man/man9/hashinit.9 b/share/man/man9/hashinit.9
index 7da84f42791..b67087d4e33 100644
--- a/share/man/man9/hashinit.9
+++ b/share/man/man9/hashinit.9
@@ -1,4 +1,4 @@
-.\" $OpenBSD: hashinit.9,v 1.7 2016/09/02 18:32:39 jmc Exp $
+.\" $OpenBSD: hashinit.9,v 1.8 2016/09/24 18:35:52 tedu Exp $
.\"
.\" Copyright (c) 2001 Tobias Weingartner
.\" All rights reserved.
@@ -25,18 +25,19 @@
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd $Mdocdate: September 2 2016 $
+.Dd $Mdocdate: September 24 2016 $
.Dt HASHINIT 9
.Os
.Sh NAME
-.Nm hashinit
-.\" This should be ported from netbsd as well...
-.\" .Nm hashdone
+.Nm hashinit ,
+.Nm hashfree
.Nd kernel hashtable functions
.Sh SYNOPSIS
.In sys/systm.h
.Ft void *
.Fn hashinit "int num" "int type" "int flags" "u_long *mask"
+.Ft void
+.Fn hashfree "void *hash" "int num" "int type"
.Sh DESCRIPTION
The
.Fn hashinit
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 *, ...)