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 rwakeup(Rendez*);
extern int rwakeupall(Rendez*); extern int rwakeupall(Rendez*);
extern void** privalloc(void); extern void** privalloc(void);
extern void privfree(void**);
/* /*
* network dialing * network dialing

View file

@ -1,6 +1,6 @@
.TH PRIVALLOC 2 .TH PRIVALLOC 2
.SH NAME .SH NAME
privalloc, privfree \- per-process private storage management privalloc \- per-process private storage management
.SH SYNOPSIS .SH SYNOPSIS
.B #include <u.h> .B #include <u.h>
.br .br
@ -9,9 +9,6 @@ privalloc, privfree \- per-process private storage management
.PP .PP
.B .B
void** privalloc(void) void** privalloc(void)
.PP
.B
void privfree(void **p)
.SH DESCRIPTION .SH DESCRIPTION
.I Privalloc .I Privalloc
returns a pointer to a per-process private storage location. returns a pointer to a per-process private storage location.
@ -20,16 +17,6 @@ even if they share the same data segments.
It returns It returns
.B nil .B nil
if there are no free slots available. 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 .SH SOURCE
.B /sys/src/libc/9sys/privalloc.c .B /sys/src/libc/9sys/privalloc.c
.SH SEE ALSO .SH SEE ALSO

View file

@ -2,8 +2,6 @@
#include <libc.h> #include <libc.h>
static Lock privlock; static Lock privlock;
static int privinit;
static void **privs;
extern void **_privates; extern void **_privates;
extern int _nprivates; extern int _nprivates;
@ -12,34 +10,13 @@ void **
privalloc(void) privalloc(void)
{ {
void **p; void **p;
int i;
lock(&privlock); lock(&privlock);
if(!privinit){ if(_nprivates > 0)
privinit = 1; p = &_privates[--_nprivates];
if(_nprivates){ else
_privates[0] = 0; p = nil;
for(i = 1; i < _nprivates; i++)
_privates[i] = &_privates[i - 1];
privs = &_privates[i - 1];
}
}
p = privs;
if(p != nil){
privs = *p;
*p = nil;
}
unlock(&privlock); unlock(&privlock);
return p; return p;
} }
void
privfree(void **p)
{
lock(&privlock);
if(p != nil && privinit){
*p = privs;
privs = p;
}
unlock(&privlock);
}