code: mafs

ref: 5c21eca829380c28769f79beabb7cc51f1787f97
dir: /misc.c/

View raw version
#include <u.h>
#include <libc.h>
#include "dat.h"
#include "fns.h"

void
chkrunlock(RWLock *q)
{
	if(q->readers <= 0)
		print("runlock(%#p): not locked: pc %#p\n",
			q, getcallerpc(&q));
	else
		runlock(q);
}

void
chkwunlock(RWLock *q)
{
	if(q->writer <= 0)
		print("wunlock(%#p): not locked: pc %#p\n",
			q, getcallerpc(&q));
	else
		wunlock(q);
}

void
chkqunlock(QLock *q)
{
	if(q->locked == 0)
		print("qunlock(%#p): not locked: pc %#p\n",
			q, getcallerpc(&q));
	else
		qunlock(q);
}

int
dprint(char *fmt, ...)
{
	static char buf[2048];
	static QLock lk;
	va_list va;
	int rc;

	qlock(&lk);
	va_start(va, fmt);
	snprint(buf, 2048, "%d %llud: %s", getpid(), nsec(), fmt);
	rc = vfprint(2, buf, va);
	va_end(va);
	qunlock(&lk);
	return rc;
}

void
panic(char *fmt, ...)
{
	char buf[8192], *s;
	va_list arg;


	s = buf;
	s += sprint(s, "%s %d: ", argv0, getpid());
	va_start(arg, fmt);
	s = vseprint(s, buf + sizeof(buf) / sizeof(*buf), fmt, arg);
	va_end(arg);
	*s++ = '\n';
	write(2, buf, s - buf);
	abort();
	exits(buf);
}