svn commit: r299040 - head/sys/kern

Sepherosa Ziehau sephe at FreeBSD.org
Wed May 4 03:07:53 UTC 2016


Author: sephe
Date: Wed May  4 03:07:52 2016
New Revision: 299040
URL: https://svnweb.freebsd.org/changeset/base/299040

Log:
  kern: Factor out function to convert hash flags to malloc(9) flags
  
  Suggested by:	jhb
  Reviewed by:	jhb, kib
  Sponsored by:	Microsoft OSTC
  Differential Revision:	https://reviews.freebsd.org/D6184

Modified:
  head/sys/kern/subr_hash.c

Modified: head/sys/kern/subr_hash.c
==============================================================================
--- head/sys/kern/subr_hash.c	Wed May  4 02:23:14 2016	(r299039)
+++ head/sys/kern/subr_hash.c	Wed May  4 03:07:52 2016	(r299040)
@@ -41,6 +41,13 @@ __FBSDID("$FreeBSD$");
 #include <sys/systm.h>
 #include <sys/malloc.h>
 
+static __inline int
+hash_mflags(int flags)
+{
+
+	return ((flags & HASH_NOWAIT) ? M_NOWAIT : M_WAITOK);
+}
+
 /*
  * General routine to allocate a hash table with control of memory flags.
  */
@@ -61,13 +68,8 @@ hashinit_flags(int elements, struct mall
 		continue;
 	hashsize >>= 1;
 
-	if (flags & HASH_NOWAIT)
-		hashtbl = malloc((u_long)hashsize * sizeof(*hashtbl),
-		    type, M_NOWAIT);
-	else
-		hashtbl = malloc((u_long)hashsize * sizeof(*hashtbl),
-		    type, M_WAITOK);
-
+	hashtbl = malloc((u_long)hashsize * sizeof(*hashtbl), type,
+	    hash_mflags(flags));
 	if (hashtbl != NULL) {
 		for (i = 0; i < hashsize; i++)
 			LIST_INIT(&hashtbl[i]);
@@ -112,7 +114,7 @@ phashinit_flags(int elements, struct mal
 {
 	long hashsize;
 	LIST_HEAD(generic, generic) *hashtbl;
-	int i, m_flags;
+	int i;
 
 	KASSERT(elements > 0, ("%s: bad elements", __func__));
 	/* Exactly one of HASH_WAITOK and HASH_NOWAIT must be set. */
@@ -127,8 +129,8 @@ phashinit_flags(int elements, struct mal
 	}
 	hashsize = primes[i - 1];
 
-	m_flags = (flags & HASH_NOWAIT) ? M_NOWAIT : M_WAITOK;
-	hashtbl = malloc((u_long)hashsize * sizeof(*hashtbl), type, m_flags);
+	hashtbl = malloc((u_long)hashsize * sizeof(*hashtbl), type,
+	    hash_mflags(flags));
 	if (hashtbl == NULL)
 		return (NULL);
 


More information about the svn-src-head mailing list