ref: 7562da90e562e65156042574e088d4359a8fccba
parent: 431cbe35f6a3f9c0c74d11937dfa7e06da34ecde
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun Sep 6 16:43:05 EDT 2015
libc: remove privfree(), simplify privalloc()
--- a/sys/include/libc.h
+++ b/sys/include/libc.h
@@ -474,7 +474,6 @@
extern int rwakeup(Rendez*);
extern int rwakeupall(Rendez*);
extern void** privalloc(void);
-extern void privfree(void**);
/*
* network dialing
--- 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 <u.h>
.br
@@ -9,9 +9,6 @@
.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 @@
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
--- a/sys/src/libc/9sys/privalloc.c
+++ b/sys/src/libc/9sys/privalloc.c
@@ -2,8 +2,6 @@
#include <libc.h>
static Lock privlock;
-static int privinit;
-static void **privs;
extern void **_privates;
extern int _nprivates;
@@ -12,34 +10,13 @@
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);
+ return p;
}