summaryrefslogtreecommitdiff
path: root/lib/resource.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/resource.c')
-rw-r--r--lib/resource.c45
1 files changed, 28 insertions, 17 deletions
diff --git a/lib/resource.c b/lib/resource.c
index 89e559b4..94b8d019 100644
--- a/lib/resource.c
+++ b/lib/resource.c
@@ -14,6 +14,7 @@
#include "nest/bird.h"
#include "lib/resource.h"
#include "lib/string.h"
+#include "lib/rcu.h"
/**
* DOC: Resource pools
@@ -29,13 +30,7 @@
* is freed upon shutdown of the module.
*/
-struct pool {
- resource r;
- list inside;
- const char *name;
-};
-
-static void pool_dump(resource *);
+static void pool_dump(resource *, unsigned);
static void pool_free(resource *);
static resource *pool_lookup(resource *, unsigned long);
static struct resmem pool_memsize(resource *P);
@@ -51,8 +46,6 @@ static struct resclass pool_class = {
pool root_pool;
-static int indent;
-
/**
* rp_new - create a resource pool
* @p: parent pool
@@ -100,16 +93,14 @@ pool_free(resource *P)
}
static void
-pool_dump(resource *P)
+pool_dump(resource *P, unsigned indent)
{
pool *p = (pool *) P;
resource *r;
debug("%s\n", p->name);
- indent += 3;
WALK_LIST(r, p->inside)
- rdump(r);
- indent -= 3;
+ rdump(r, indent + 3);
}
static struct resmem
@@ -199,7 +190,7 @@ rfree(void *res)
* It works by calling a class-specific dump function.
*/
void
-rdump(void *res)
+rdump(void *res, unsigned indent)
{
char x[16];
resource *r = res;
@@ -209,7 +200,7 @@ rdump(void *res)
if (r)
{
debug("%s ", r->class->name);
- r->class->dump(r);
+ r->class->dump(r, indent);
}
else
debug("NULL\n");
@@ -269,7 +260,7 @@ rlookup(unsigned long a)
debug("Looking up %08lx\n", a);
if (r = pool_lookup(&root_pool.r, a))
- rdump(r);
+ rdump(r, 3);
else
debug("Not found.\n");
}
@@ -284,6 +275,7 @@ rlookup(unsigned long a)
void
resource_init(void)
{
+ rcu_init();
resource_sys_init();
root_pool.r.class = &pool_class;
@@ -292,6 +284,25 @@ resource_init(void)
tmp_init(&root_pool);
}
+_Thread_local struct tmp_resources tmp_res;
+
+void
+tmp_init(pool *p)
+{
+ tmp_res.lp = lp_new_default(p);
+ tmp_res.parent = p;
+ tmp_res.pool = rp_new(p, "TMP");
+}
+
+void
+tmp_flush(void)
+{
+ lp_flush(tmp_linpool);
+ rfree(tmp_res.pool);
+ tmp_res.pool = rp_new(tmp_res.parent, "TMP");
+}
+
+
/**
* DOC: Memory blocks
*
@@ -316,7 +327,7 @@ static void mbl_free(resource *r UNUSED)
{
}
-static void mbl_debug(resource *r)
+static void mbl_debug(resource *r, unsigned indent UNUSED)
{
struct mblock *m = (struct mblock *) r;