aboutsummaryrefslogtreecommitdiff
path: root/src/libthread/thread.c
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2005-09-26 12:05:26 +0000
committerrsc <devnull@localhost>2005-09-26 12:05:26 +0000
commit6dde87f83ccd2eac808c1539ac40617695f2809f (patch)
tree03f81bc69f8c7c711e0c53bbaa00155959bc66e2 /src/libthread/thread.c
parent391363f510a13378b3f3515e763b9c754a242fe0 (diff)
downloadplan9port-6dde87f83ccd2eac808c1539ac40617695f2809f.tar.gz
plan9port-6dde87f83ccd2eac808c1539ac40617695f2809f.tar.bz2
plan9port-6dde87f83ccd2eac808c1539ac40617695f2809f.zip
Print information on SIGQUIT, SIGINFO.
Diffstat (limited to 'src/libthread/thread.c')
-rw-r--r--src/libthread/thread.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/libthread/thread.c b/src/libthread/thread.c
index da4afe12..145a5033 100644
--- a/src/libthread/thread.c
+++ b/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!");
@@ -727,3 +729,42 @@ 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;
+}
+
+