Plan 9 from Bell Labs’s /usr/web/sources/plan9/sys/src/libc/9sys/privalloc.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


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

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].