commit b84d3c24b90fd23b9aa8808ec9ec66995bac2301
parent 4bf8e34798442687c59ed815248bdc4ab71e8759
Author: Roberto E. Vargas Caballero <roberto.vargas@midokura.com>
Date: Fri, 18 Nov 2022 14:43:52 +0100
os9: Add freemap()
We add a pool of objects that can be reused if they are freed.
Diffstat:
2 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/include/os9/os9.h b/include/os9/os9.h
@@ -112,6 +112,7 @@ struct map {
phyaddr_t pa;
uintptr_t va;
size_t siz;
+ Map *next;
};
/*
diff --git a/src/os9/proc.c b/src/os9/proc.c
@@ -18,6 +18,11 @@ static struct {
mutex_t m;
} fdspool;
+static struct {
+ Map *list;
+ mutex_t m;
+} mappool;
+
/* per cpu globals */
Task *proc;
long long now;
@@ -298,8 +303,15 @@ newmap(Map *from)
{
Map *mp;
- if ((mp = alloc(sizeof(*mp))) == NULL)
- return NULL;
+ lock(&mappool.m);
+ if (mappool.list) {
+ mp = mappool.list;
+ mappool.list = mp->next;
+ } else {
+ if ((mp = alloc(sizeof(*mp))) == NULL)
+ return NULL;
+ }
+ unlock(&mappool.m);
*mp = *from;
initref(&mp->ref);
@@ -329,7 +341,10 @@ freefds(Fdset *fds)
static void
freemap(Map *mp)
{
- /* TODO */
+ lock(&mappool.m);
+ mp->next = mappool.list;
+ mappool.list = mp;
+ unlock(&mappool.m);
}
static void