#include <9pm/u.h>
#include <9pm/libc.h>
#include <9pm/ns.h>

void
rendsleep(Rendez *r, int (*fn)(void*), void *arg)
{
	lock(&r->lk);
	assert(r->p == nil);
	if((*fn)(arg)){
		unlock(&r->lk);
		return;
	}
	r->p = getproc();
	unlock(&r->lk);
	nap();
}

Proc*
rendwakeup(Rendez *r)
{
	Proc *p;

	lock(&r->lk);
	p = r->p;
	r->p = nil;
	unlock(&r->lk);
	if(p)
		wake(p);
	return p;
}
