* General routine to allocate a hash table with control of memory flags. */
| 54 | * General routine to allocate a hash table with control of memory flags. |
| 55 | */ |
| 56 | void * |
| 57 | hashinit_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. |
no test coverage detected