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