Plan 9 from User Space's /usr/local/plan9/src/libthread/ref.c

#include "u.h"
#include "libc.h"
#include "thread.h"

static long
refadd(Ref *r, long a)
{
	long ref;

	lock(&r->lock);
	r->ref += a;
	ref = r->ref;
	unlock(&r->lock);
	return ref;
}

long
incref(Ref *r)
{
	return refadd(r, 1);
}

long
decref(Ref *r)
{
	return refadd(r, -1);
}

Space Glenda

Copyright © 2005 Lucent Technologies, Russ Cox, MIT.
See license for details.