diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2023-04-08 20:24:44 +0000 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2023-04-08 20:24:44 +0000 |
commit | bd43bd6f1ae1b1ec7ee6873d9fd6766b049802e9 (patch) | |
tree | 6b846a12ebf42feaf394de84ab663d6c3314d984 /sys/src/libc | |
parent | 26e42d115979009c9fe144e1c28f740485537674 (diff) |
libc: Add poolreset() function
This is intended for the secrmem pool in the kernel,
but could also be used for temporary pools to
recover the memory used by the arenas.
Diffstat (limited to 'sys/src/libc')
-rw-r--r-- | sys/src/libc/port/mkfile | 2 | ||||
-rw-r--r-- | sys/src/libc/port/pool.c | 37 |
2 files changed, 39 insertions, 0 deletions
diff --git a/sys/src/libc/port/mkfile b/sys/src/libc/port/mkfile index 557f1d7fa..683e6c583 100644 --- a/sys/src/libc/port/mkfile +++ b/sys/src/libc/port/mkfile @@ -131,6 +131,8 @@ UPDATE=mkfile\ profile.$O: /sys/include/tos.h +malloc.$O pool.$O: /sys/include/pool.h + runenorm.$O: runenormdata runenorm.c runetotype.$O: runetotypedata runetotype.c runeistype.$O: runeistypedata runeistype.c diff --git a/sys/src/libc/port/pool.c b/sys/src/libc/port/pool.c index 546d5776a..34254f7f5 100644 --- a/sys/src/libc/port/pool.c +++ b/sys/src/libc/port/pool.c @@ -1345,6 +1345,43 @@ poolisoverlap(Pool *p, void *v, ulong n) return a != nil; } +void +poolreset(Pool *p) +{ + Arena *a; + + if(p == nil) + return; + + p->lock(p); + paranoia { + poolcheckl(p); + } + verbosity { + pooldumpl(p); + } + p->cursize = 0; + p->curfree = 0; + p->curalloc = 0; + p->lastcompact = p->nfree = 0; + p->freeroot = nil; + a = p->arenalist; + p->arenalist = nil; + LOG(p, "poolreset %p\n", p); + p->unlock(p); + + while(a != nil){ + Arena *next = a->down; + ulong asize = a->asize; + antagonism { + memmark(a, 0xFF, asize); + } + if(p->free) + p->free(a, asize); + a = next; + } +} + /* * Debugging */ |