From 7562da90e562e65156042574e088d4359a8fccba Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sun, 6 Sep 2015 20:43:05 +0200 Subject: [PATCH] libc: remove privfree(), simplify privalloc() --- sys/include/libc.h | 1 - sys/man/2/privalloc | 15 +-------------- sys/src/libc/9sys/privalloc.c | 33 +++++---------------------------- 3 files changed, 6 insertions(+), 43 deletions(-) diff --git a/sys/include/libc.h b/sys/include/libc.h index ba18303a3..bd273d8b8 100644 --- a/sys/include/libc.h +++ b/sys/include/libc.h @@ -474,7 +474,6 @@ extern void rsleep(Rendez*); /* unlocks r->l, sleeps, locks r->l again */ extern int rwakeup(Rendez*); extern int rwakeupall(Rendez*); extern void** privalloc(void); -extern void privfree(void**); /* * network dialing diff --git a/sys/man/2/privalloc b/sys/man/2/privalloc index 20dd0bf2f..0634517e6 100644 --- a/sys/man/2/privalloc +++ b/sys/man/2/privalloc @@ -1,6 +1,6 @@ .TH PRIVALLOC 2 .SH NAME -privalloc, privfree \- per-process private storage management +privalloc \- per-process private storage management .SH SYNOPSIS .B #include .br @@ -9,9 +9,6 @@ privalloc, privfree \- per-process private storage management .PP .B void** privalloc(void) -.PP -.B -void privfree(void **p) .SH DESCRIPTION .I Privalloc returns a pointer to a per-process private storage location. @@ -20,16 +17,6 @@ even if they share the same data segments. It returns .B nil if there are no free slots available. -.PP -.I Privfree -releases a location allocated with -.IR privalloc . -It is legal to call -.I privfree -with -.I p -set to -.BR nil . .SH SOURCE .B /sys/src/libc/9sys/privalloc.c .SH SEE ALSO diff --git a/sys/src/libc/9sys/privalloc.c b/sys/src/libc/9sys/privalloc.c index 907485e2f..3117ffc56 100644 --- a/sys/src/libc/9sys/privalloc.c +++ b/sys/src/libc/9sys/privalloc.c @@ -2,8 +2,6 @@ #include static Lock privlock; -static int privinit; -static void **privs; extern void **_privates; extern int _nprivates; @@ -12,34 +10,13 @@ void ** privalloc(void) { void **p; - int i; lock(&privlock); - if(!privinit){ - privinit = 1; - if(_nprivates){ - _privates[0] = 0; - for(i = 1; i < _nprivates; i++) - _privates[i] = &_privates[i - 1]; - privs = &_privates[i - 1]; - } - } - p = privs; - if(p != nil){ - privs = *p; - *p = nil; - } + if(_nprivates > 0) + p = &_privates[--_nprivates]; + else + p = nil; unlock(&privlock); + return p; } - -void -privfree(void **p) -{ - lock(&privlock); - if(p != nil && privinit){ - *p = privs; - privs = p; - } - unlock(&privlock); -}