From owner-svn-src-all@freebsd.org Wed May 4 03:07:53 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C95ADB2C513; Wed, 4 May 2016 03:07:53 +0000 (UTC) (envelope-from sephe@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 81A7D1278; Wed, 4 May 2016 03:07:53 +0000 (UTC) (envelope-from sephe@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u4437q5f097599; Wed, 4 May 2016 03:07:52 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u4437qSc097598; Wed, 4 May 2016 03:07:52 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201605040307.u4437qSc097598@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Wed, 4 May 2016 03:07:52 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r299040 - head/sys/kern X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 May 2016 03:07:53 -0000 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 #include +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);