44#include <sys/malloc.h>
50 return ((
flags & HASH_NOWAIT) ? M_NOWAIT : M_WAITOK);
63 KASSERT(elements > 0, (
"%s: bad elements", __func__));
65 KASSERT((
flags & HASH_WAITOK) ^ (
flags & HASH_NOWAIT),
66 (
"Bad flags (0x%x) passed to hashinit_flags",
flags));
68 for (hashsize = 1; hashsize <= elements; hashsize <<= 1)
72 hashtbl =
malloc((u_long)hashsize *
sizeof(*hashtbl),
type,
74 if (hashtbl != NULL) {
75 for (i = 0; i < hashsize; i++)
76 LIST_INIT(&hashtbl[i]);
77 *hashmask = hashsize - 1;
95 LIST_HEAD(generic, generic) *hashtbl, *hp;
98 for (hp = hashtbl; hp <= &hashtbl[hashmask]; hp++)
99 KASSERT(LIST_EMPTY(hp), (
"%s: hashtbl %p not empty "
100 "(malloc type %s)", __func__, hashtbl,
type->ks_shortdesc));
104static const int primes[] = { 1, 13, 31, 61, 127, 251, 509, 761, 1021, 1531,
105 2039, 2557, 3067, 3583, 4093, 4603, 5119, 5623, 6143,
106 6653, 7159, 7673, 8191, 12281, 16381, 24571, 32749 };
107#define NPRIMES nitems(primes)
119 KASSERT(elements > 0, (
"%s: bad elements", __func__));
121 KASSERT((
flags & HASH_WAITOK) ^ (
flags & HASH_NOWAIT),
122 (
"Bad flags (0x%x) passed to phashinit_flags",
flags));
124 for (i = 1, hashsize =
primes[1]; hashsize <= elements;) {
132 hashtbl =
malloc((u_long)hashsize *
sizeof(*hashtbl),
type,
137 for (i = 0; i < hashsize; i++)
138 LIST_INIT(&hashtbl[i]);
139 *nentries = hashsize;
device_property_type_t type
void *() malloc(size_t size, struct malloc_type *mtp, int flags)
void free(void *addr, struct malloc_type *mtp)
void * phashinit(int elements, struct malloc_type *type, u_long *nentries)
static const int primes[]
void * hashinit_flags(int elements, struct malloc_type *type, u_long *hashmask, int flags)
static __inline int hash_mflags(int flags)
void * phashinit_flags(int elements, struct malloc_type *type, u_long *nentries, int flags)
void hashdestroy(void *vhashtbl, struct malloc_type *type, u_long hashmask)
void * hashinit(int elements, struct malloc_type *type, u_long *hashmask)