Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/sys/kern/subr_pool.c,v retrieving revision 1.177 retrieving revision 1.178 diff -u -p -r1.177 -r1.178 --- src/sys/kern/subr_pool.c 2009/10/20 17:24:22 1.177 +++ src/sys/kern/subr_pool.c 2009/12/30 18:57:17 1.178 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_pool.c,v 1.177 2009/10/20 17:24:22 jym Exp $ */ +/* $NetBSD: subr_pool.c,v 1.178 2009/12/30 18:57:17 elad Exp $ */ /*- * Copyright (c) 1997, 1999, 2000, 2002, 2007, 2008 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: subr_pool.c,v 1.177 2009/10/20 17:24:22 jym Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_pool.c,v 1.178 2009/12/30 18:57:17 elad Exp $"); #include "opt_ddb.h" #include "opt_pool.h" @@ -104,6 +104,9 @@ static struct pool *drainpp; static kmutex_t pool_head_lock; static kcondvar_t pool_busy; +/* This lock protects initialization of a potentially shared pool allocator */ +static kmutex_t pool_allocator_lock; + typedef uint32_t pool_item_bitmap_t; #define BITMAP_SIZE (CHAR_BIT * sizeof(pool_item_bitmap_t)) #define BITMAP_MASK (BITMAP_SIZE - 1) @@ -604,6 +607,8 @@ pool_subsystem_init(void) pool_init(&cache_cpu_pool, sizeof(pool_cache_cpu_t), coherency_unit, 0, 0, "pcachecpu", &pool_allocator_nointr, IPL_NONE); + + mutex_init(&pool_allocator_lock, MUTEX_DEFAULT, IPL_NONE); } /* @@ -650,7 +655,8 @@ pool_init(struct pool *pp, size_t size, palloc = &pool_allocator_nointr_fullpage; } #endif /* POOL_SUBPAGE */ - if ((palloc->pa_flags & PA_INITIALIZED) == 0) { + mutex_enter(&pool_allocator_lock); + if (palloc->pa_refcnt++ == 0) { if (palloc->pa_pagesz == 0) palloc->pa_pagesz = PAGE_SIZE; @@ -663,8 +669,8 @@ pool_init(struct pool *pp, size_t size, if (palloc->pa_backingmapptr != NULL) { pa_reclaim_register(palloc); } - palloc->pa_flags |= PA_INITIALIZED; } + mutex_exit(&pool_allocator_lock); if (align == 0) align = ALIGN(1); @@ -892,6 +898,11 @@ pool_destroy(struct pool *pp) TAILQ_REMOVE(&pp->pr_alloc->pa_list, pp, pr_alloc_list); mutex_exit(&pp->pr_alloc->pa_lock); + mutex_enter(&pool_allocator_lock); + if (--pp->pr_alloc->pa_refcnt == 0) + mutex_destroy(&pp->pr_alloc->pa_lock); + mutex_exit(&pool_allocator_lock); + mutex_enter(&pp->pr_lock); KASSERT(pp->pr_cache == NULL);