Commit Diff


commit - 391363f510a13378b3f3515e763b9c754a242fe0
commit + 6dde87f83ccd2eac808c1539ac40617695f2809f
blob - da4afe12e5a8e9e3a1d69b4f5d7ee96c66c25174
blob + 145a503308788e0f1c415788e5f36b1e75806c3a
--- src/libthread/thread.c
+++ src/libthread/thread.c
@@ -16,6 +16,7 @@ static	void		addthreadinproc(Proc*, _Thread*);
 static	void		delthreadinproc(Proc*, _Thread*);
 static	void		contextswitch(Context *from, Context *to);
 static	void		procscheduler(Proc*);
+static	int		threadinfo(void*, char*);
 
 static void
 _threaddebug(char *fmt, ...)
@@ -614,6 +615,7 @@ main(int argc, char **argv)
 	_threadsetproc(p);
 	if(mainstacksize == 0)
 		mainstacksize = 256*1024;
+	atnotify(threadinfo, 1);
 	_threadcreate(p, threadmainstart, nil, mainstacksize);
 	procscheduler(p);
 	sysfatal("procscheduler returned in threadmain!");
@@ -726,4 +728,43 @@ void
 threadnotify(int (*f)(void*, char*), int in)
 {
 	atnotify(f, in);
+}
+
+static int
+onrunqueue(Proc *p, _Thread *t)
+{
+	_Thread *tt;
+
+	for(tt=p->runqueue.head; tt; tt=tt->next)
+		if(tt == t)
+			return 1;
+	return 0;
 }
+
+/*
+ * print state - called from SIGINFO
+ */
+static int
+threadinfo(void *v, char *s)
+{
+	Proc *p;
+	_Thread *t;
+
+	if(strcmp(s, "quit") != 0 && strcmp(s, "sys: status request") != 0)
+		return 0;
+
+	for(p=_threadprocs; p; p=p->next){
+		fprint(2, "proc %p %s%s\n", (void*)p->osprocid, p->msg,
+			p->sysproc ? " (sysproc)": "");
+		for(t=p->allthreads.head; t; t=t->allnext){
+			fprint(2, "\tthread %d %s: %s %s\n", 
+				t->id, 
+				t == p->thread ? "Running" : 
+				onrunqueue(p, t) ? "Ready" : "Sleeping",
+				t->state, t->name);
+		}
+	}
+	return 1;
+}
+
+