commit 4bf8e34798442687c59ed815248bdc4ab71e8759
parent 876558ef0200bc66ec6271c929e8cb6857137e35
Author: Roberto E. Vargas Caballero <roberto.vargas@midokura.com>
Date: Fri, 18 Nov 2022 14:43:52 +0100
os9: Add freefds()
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
@@ -169,6 +169,7 @@ struct fdset {
Ref ref;
mutex_t m;
Chan fdset[NR_CHANS];
+ Fdset *next;
};
/**
diff --git a/src/os9/proc.c b/src/os9/proc.c
@@ -13,6 +13,11 @@ static struct {
mutex_t m;
} nspool;
+static struct {
+ Fdset *list;
+ mutex_t m;
+} fdspool;
+
/* per cpu globals */
Task *proc;
long long now;
@@ -272,8 +277,15 @@ newfds(Fdset *from)
{
Fdset *fds;
- if ((fds = alloc(sizeof(*fds))) == NULL)
- return NULL;
+ lock(&fdspool.m);
+ if (fdspool.list) {
+ fds = fdspool.list;
+ fdspool.list = fds->next;
+ } else {
+ if ((fds = alloc(sizeof(*fds))) == NULL)
+ return NULL;
+ }
+ unlock(&fdspool.m);
*fds = (from) ? *from : (Fdset) {0};
initref(&fds->ref);
@@ -308,7 +320,10 @@ freespace(Nspace *ns)
static void
freefds(Fdset *fds)
{
- /* TODO */
+ lock(&fdspool.m);
+ fds->next = fdspool.list;
+ fdspool.list = fds;
+ unlock(&fdspool.m);
}
static void