MCPcopy Index your code
hub / github.com/F-Stack/f-stack / hashinit_flags

Function hashinit_flags

lib/ff_kern_subr.c:55–83  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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

Callers 3

hashinitFunction · 0.70
ng_name_rehashFunction · 0.70
ng_ID_rehashFunction · 0.70

Calls 4

LIST_HEADFunction · 0.85
mallocFunction · 0.85
panicFunction · 0.70
hash_mflagsFunction · 0.70

Tested by

no test coverage detected