Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern Use pool_init() rather then pool_create().



details:   https://anonhg.NetBSD.org/src/rev/7258b6d21289
branches:  trunk
changeset: 509663:7258b6d21289
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Wed May 09 23:38:20 2001 +0000

description:
Use pool_init() rather then pool_create().

diffstat:

 sys/kern/subr_extent.c |  49 +++++++++++++++++++++++++++----------------------
 1 files changed, 27 insertions(+), 22 deletions(-)

diffs (117 lines):

diff -r 9f5d08c3b455 -r 7258b6d21289 sys/kern/subr_extent.c
--- a/sys/kern/subr_extent.c    Wed May 09 23:20:59 2001 +0000
+++ b/sys/kern/subr_extent.c    Wed May 09 23:38:20 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: subr_extent.c,v 1.40 2001/04/27 00:06:11 marcus Exp $  */
+/*     $NetBSD: subr_extent.c,v 1.41 2001/05/09 23:38:20 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1996, 1998 The NetBSD Foundation, Inc.
@@ -81,7 +81,7 @@
 #define        \
 wakeup(chan)                   ((void)0)
 #define        \
-pool_get(pool, flags)          malloc(pool->pr_size,0,0)
+pool_get(pool, flags)          malloc((pool)->pr_size,0,0)
 #define        \
 pool_put(pool, rp)             free(rp,0)
 #define        \
@@ -100,7 +100,6 @@
 #define        KMEM_IS_RUNNING                 (1)
 #endif
 
-static struct pool *expool_create __P((void));
 static void extent_insert_and_optimize __P((struct extent *, u_long, u_long,
            int, struct extent_region *, struct extent_region *));
 static struct extent_region *extent_alloc_region_descriptor
@@ -108,7 +107,9 @@
 static void extent_free_region_descriptor __P((struct extent *,
            struct extent_region *));
 
-static struct pool *expool;
+static struct pool expool;
+static struct simplelock expool_init_slock = SIMPLELOCK_INITIALIZER;
+static int expool_initialized;
 
 /*
  * Macro to align to an arbitrary power-of-two boundary.
@@ -121,16 +122,25 @@
  * (This is deferred until one of our callers thinks we can malloc()).
  */
 
-static struct pool *expool_create()
+static __inline void
+expool_init(void)
 {
+
+       simple_lock(&expool_init_slock);
+       if (expool_initialized) {
+               simple_unlock(&expool_init_slock);
+               return;
+       }
+
 #if defined(_KERNEL)
-       expool = pool_create(sizeof(struct extent_region), 0, 0,
-                            0, "extent", 0, 0, 0, 0);
+       pool_init(&expool, sizeof(struct extent_region), 0, 0, 0,
+           "extent", 0, 0, 0, 0);
 #else
-       expool = (struct pool *)malloc(sizeof(*expool),0,0);
-       expool->pr_size = sizeof(struct extent_region);
+       expool.pr_size = sizeof(struct extent_region);
 #endif
-       return (expool);
+
+       expool_initialized = 1;
+       simple_unlock(&expool_init_slock);
 }
 
 /*
@@ -197,11 +207,9 @@
                }
        } else {
                s = splhigh();
-               if (expool == NULL)
-                       expool_create();
+               if (expool_initialized == 0)
+                       expool_init();
                splx(s);
-               if (expool == NULL)
-                       return (NULL);
 
                ex = (struct extent *)malloc(sizeof(struct extent),
                    mtype, (flags & EX_WAITOK) ? M_WAITOK : M_NOWAIT);
@@ -1082,12 +1090,9 @@
 
  alloc:
        s = splhigh();
-       if (expool == NULL && !expool_create()) {
-               splx(s);
-               return (NULL);
-       }
-
-       rp = pool_get(expool, (flags & EX_WAITOK) ? PR_WAITOK : 0);
+       if (expool_initialized == 0)
+               expool_init();
+       rp = pool_get(&expool, (flags & EX_WAITOK) ? PR_WAITOK : 0);
        splx(s);
 
        if (rp != NULL)
@@ -1124,7 +1129,7 @@
                                goto wake_em_up;
                        } else {
                                s = splhigh();
-                               pool_put(expool, rp);
+                               pool_put(&expool, rp);
                                splx(s);
                        }
                } else {
@@ -1145,7 +1150,7 @@
         * We know it's dynamically allocated if we get here.
         */
        s = splhigh();
-       pool_put(expool, rp);
+       pool_put(&expool, rp);
        splx(s);
 }
 



Home | Main Index | Thread Index | Old Index