9os

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 876558ef0200bc66ec6271c929e8cb6857137e35
parent fe66fae763439a8da67237ac99803cab03bc0f74
Author: Roberto E. Vargas Caballero <roberto.vargas@midokura.com>
Date:   Fri, 18 Nov 2022 14:43:52 +0100

os9: Add freespace()

We add a pool of objects that can be reused if they are freed.

Diffstat:
Minclude/os9/os9.h | 1+
Msrc/os9/proc.c | 21++++++++++++++++++---
2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/include/os9/os9.h b/include/os9/os9.h @@ -162,6 +162,7 @@ struct nspace { Ref ref; mutex_t m; struct mpoint mpoints[NR_MPOINTS]; + Nspace *next; }; struct fdset { diff --git a/src/os9/proc.c b/src/os9/proc.c @@ -8,6 +8,11 @@ static Task tasktab[NR_TASKS]; static mutex_t procm; +static struct { + Nspace *list; + mutex_t m; +} nspool; + /* per cpu globals */ Task *proc; long long now; @@ -246,8 +251,15 @@ newspace(Nspace *from) { Nspace *ns; - if ((ns = alloc(sizeof(*ns))) == NULL) - return NULL; + lock(&nspool.m); + if (nspool.list) { + ns = nspool.list; + nspool.list = ns->next; + } else { + if ((ns = alloc(sizeof(*ns))) == NULL) + return NULL; + } + unlock(&nspool.m); *ns = (from) ? *from : (Nspace) {0}; initref(&ns->ref); @@ -287,7 +299,10 @@ newmap(Map *from) static void freespace(Nspace *ns) { - /* TODO */ + lock(&nspool.m); + ns->next = nspool.list; + nspool.list = ns; + unlock(&nspool.m); } static void