Blob


1 #include "threadimpl.h"
3 int _threaddebuglevel;
5 void
6 __threaddebug(ulong flag, char *fmt, ...)
7 {
8 char buf[128];
9 va_list arg;
10 Fmt f;
11 Proc *p;
13 if((_threaddebuglevel&flag) == 0)
14 return;
16 fmtfdinit(&f, 2, buf, sizeof buf);
18 p = _threadgetproc();
19 if(p==nil)
20 fmtprint(&f, "noproc ");
21 else if(p->thread)
22 fmtprint(&f, "%d.%d ", p->pid, p->thread->id);
23 else
24 fmtprint(&f, "%d._ ", p->pid);
26 va_start(arg, fmt);
27 fmtvprint(&f, fmt, arg);
28 va_end(arg);
29 fmtprint(&f, "\n");
30 fmtfdflush(&f);
31 }
33 void
34 _threadassert(char *s)
35 {
36 char buf[256];
37 int n;
38 Proc *p;
40 p = _threadgetproc();
41 if(p && p->thread)
42 n = sprint(buf, "%d.%d ", p->pid, p->thread->id);
43 else
44 n = 0;
45 snprint(buf+n, sizeof(buf)-n, "%s: assertion failed\n", s);
46 write(2, buf, strlen(buf));
47 abort();
48 }