ref: 8a3b388ffee44db7d878296cb83660139e749962
dir: /sys/src/libc/9sys/privalloc.c/
#include <u.h> #include <libc.h> static Lock privlock; static int privinit; static void **privs; extern void **_privates; extern int _nprivates; 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; } unlock(&privlock); return p; } void privfree(void **p) { lock(&privlock); if(p != nil && privinit){ *p = privs; privs = p; } unlock(&privlock); }