libc: remove privfree(), simplify privalloc()

This commit is contained in:
cinap_lenrek 2015-09-06 20:43:05 +02:00
parent 431cbe35f6
commit 7562da90e5
3 changed files with 6 additions and 43 deletions

View file

@ -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

View file

@ -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 @@ 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

View file

@ -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 @@ 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);
}