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