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

Function phashinit_flags

freebsd/kern/subr_hash.c:113–141  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

111 * memory flags.
112 */
113void *
114phashinit_flags(int elements, struct malloc_type *type, u_long *nentries, int flags)
115{
116 long hashsize, i;
117 LIST_HEAD(generic, generic) *hashtbl;
118
119 KASSERT(elements > 0, ("%s: bad elements", __func__));
120 /* Exactly one of HASH_WAITOK and HASH_NOWAIT must be set. */
121 KASSERT((flags & HASH_WAITOK) ^ (flags & HASH_NOWAIT),
122 ("Bad flags (0x%x) passed to phashinit_flags", flags));
123
124 for (i = 1, hashsize = primes[1]; hashsize <= elements;) {
125 i++;
126 if (i == NPRIMES)
127 break;
128 hashsize = primes[i];
129 }
130 hashsize = primes[i - 1];
131
132 hashtbl = malloc((u_long)hashsize * sizeof(*hashtbl), type,
133 hash_mflags(flags));
134 if (hashtbl == NULL)
135 return (NULL);
136
137 for (i = 0; i < hashsize; i++)
138 LIST_INIT(&hashtbl[i]);
139 *nentries = hashsize;
140 return (hashtbl);
141}
142
143/*
144 * Allocate and initialize a prime number sized hash table with default flag:

Callers 2

phashinitFunction · 0.70
tcp_lro_init_argsFunction · 0.50

Calls 3

LIST_HEADFunction · 0.85
mallocFunction · 0.85
hash_mflagsFunction · 0.70

Tested by

no test coverage detected