46 #include <sys/cdefs.h>
49 #include <sys/param.h>
51 #include <sys/kernel.h>
54 #include <sys/malloc.h>
55 #include <sys/mutex.h>
56 #include <sys/systm.h>
62 #ifndef MTX_POOL_LOCKBUILDER_SIZE
63 #define MTX_POOL_LOCKBUILDER_SIZE 128
65 #ifndef MTX_POOL_SLEEP_SIZE
66 #define MTX_POOL_SLEEP_SIZE 128
86 #define mtx_pool_size mtx_pool_header.mtxpool_size
87 #define mtx_pool_mask mtx_pool_header.mtxpool_mask
88 #define mtx_pool_shift mtx_pool_header.mtxpool_shift
89 #define mtx_pool_next mtx_pool_header.mtxpool_next
94 #if UINTPTR_MAX == UINT64_MAX
95 # define POINTER_BITS 64
96 # define HASH_MULTIPLIER 11400714819323198485u
98 # define POINTER_BITS 32
99 # define HASH_MULTIPLIER 2654435769u
113 KASSERT(pool != NULL, (
"_mtx_pool_find(): null pool"));
129 pool->mtx_pool_size = pool_size;
130 pool->mtx_pool_mask = pool_size - 1;
131 for (i = 1, maskbits = 0; (i & pool_size) == 0; i = i << 1)
134 pool->mtx_pool_next = 0;
135 for (i = 0; i < pool_size; ++i)
144 if (pool_size <= 0 || !powerof2(pool_size)) {
145 printf(
"WARNING: %s pool size is not a power of 2.\n",
150 ((pool_size - 1) *
sizeof (
struct mtx)),
151 M_MTXPOOL, M_WAITOK | M_ZERO);
162 for (i = pool->mtx_pool_size - 1; i >= 0; --i)
164 free(pool, M_MTXPOOL);
173 MTX_DEF | MTX_NOWITNESS | MTX_QUIET);
194 KASSERT(pool != NULL, (
"mtx_pool_alloc(): null pool"));
200 i = pool->mtx_pool_next;
201 pool->mtx_pool_next = (i + 1) & pool->mtx_pool_mask;
215 SYSINIT(mtxpooli1, SI_SUB_MTX_POOL_STATIC, SI_ORDER_FIRST,
217 SYSINIT(mtxpooli2, SI_SUB_MTX_POOL_DYNAMIC, SI_ORDER_FIRST,
#define MTX_POOL_SLEEP_SIZE
struct mtx_pool * mtxpool_sleep
struct mtxpool_header mtx_pool_header
struct mtx * mtx_pool_alloc(struct mtx_pool *pool)
struct mtxpool_header mtx_pool_header
void * malloc(unsigned long size, struct malloc_type *mtp, int flags)
struct mtx mtx_pool_ary[MTX_POOL_LOCKBUILDER_SIZE]
SYSINIT(mtxpooli1, SI_SUB_MTX_POOL_STATIC, SI_ORDER_FIRST, mtx_pool_setup_static, NULL)
struct mtx * mtx_pool_find(struct mtx_pool *pool, void *ptr)
static void mtx_pool_setup_dynamic(void *dummy __unused)
static MALLOC_DEFINE(M_MTXPOOL,"mtx_pool","mutex pool")
static struct mtx_pool_lockbuilder lockbuilder_pool
#define MTX_POOL_LOCKBUILDER_SIZE
static void mtx_pool_initialize(struct mtx_pool *pool, const char *mtx_name, int pool_size, int opts)
struct mtx_pool * mtx_pool_create(const char *mtx_name, int pool_size, int opts)
void free(void *addr, struct malloc_type *mtp)
int printf(const char *fmt,...)
struct mtx mtx_pool_ary[1]
void mtx_init(struct mtx *m, const char *name, const char *type, int opts)
struct mtx_pool * mtxpool_lockbuilder
void mtx_pool_destroy(struct mtx_pool **poolp)
void mtx_destroy(struct mtx *m)
static void mtx_pool_setup_static(void *dummy __unused)