MCPcopy Create free account
hub / github.com/F-Stack/f-stack / hashinit_flags

Function hashinit_flags

freebsd/kern/subr_hash.c:56–80  ·  view source on GitHub ↗

* General routine to allocate a hash table with control of memory flags. */

Source from the content-addressed store, hash-verified

54 * General routine to allocate a hash table with control of memory flags.
55 */
56void *
57hashinit_flags(int elements, struct malloc_type *type, u_long *hashmask,
58 int flags)
59{
60 long hashsize, i;
61 LIST_HEAD(generic, generic) *hashtbl;
62
63 KASSERT(elements > 0, ("%s: bad elements", __func__));
64 /* Exactly one of HASH_WAITOK and HASH_NOWAIT must be set. */
65 KASSERT((flags & HASH_WAITOK) ^ (flags & HASH_NOWAIT),
66 ("Bad flags (0x%x) passed to hashinit_flags", flags));
67
68 for (hashsize = 1; hashsize <= elements; hashsize <<= 1)
69 continue;
70 hashsize >>= 1;
71
72 hashtbl = malloc((u_long)hashsize * sizeof(*hashtbl), type,
73 hash_mflags(flags));
74 if (hashtbl != NULL) {
75 for (i = 0; i < hashsize; i++)
76 LIST_INIT(&hashtbl[i]);
77 *hashmask = hashsize - 1;
78 }
79 return (hashtbl);
80}
81
82/*
83 * Allocate and initialize a hash table with default flag: may sleep.

Callers 6

kqueue_expandFunction · 0.70
hashinitFunction · 0.70
ip_mrouter_initFunction · 0.50
ngs_rehashFunction · 0.50
ng_name_rehashFunction · 0.50
ng_ID_rehashFunction · 0.50

Calls 3

LIST_HEADFunction · 0.85
mallocFunction · 0.85
hash_mflagsFunction · 0.70

Tested by

no test coverage detected