| tdebugging, more pthreads crap - plan9port - [fork] Plan 9 from user space |
| git clone git://src.adamsgaard.dk/plan9port |
| Log |
| Files |
| Refs |
| README |
| LICENSE |
| --- |
| commit ba15d71b0cf27ba89d14b547d7ded643e5de6a01 |
| parent 493f3d0fbf548303a8f468ffffca8476607ee2cd |
| Author: rsc |
| Date: Fri, 22 Oct 2004 17:15:30 +0000
debugging, more pthreads crap
Diffstat:
M src/libthread/exec-unix.c | 2 ++
M src/libthread/id.c | 1 +
M src/libthread/mkfile | 3 +++
M src/libthread/note.c | 4 +---
M src/libthread/pthread.c | 5 ++++-
M src/libthread/sched.c | 12 ++++++++----
M src/libthread/ucontext.c | 9 ++++++++-
7 files changed, 27 insertions(+), 9 deletions(-)
--- |
| diff --git a/src/libthread/exec-unix.c b/src/libthread/exec-unix.c |
| t@@ -50,6 +50,7 @@ _threadexec(Channel *pidc, int fd[3], char *prog, char *args[], int freeargs)
goto Bad;
case 0:
efork(fd, pfd, prog, args);
+ _threaddebug(DBGSCHED, "exit after efork");
_exit(0);
default:
_threadafterexec();
t@@ -152,6 +153,7 @@ efork(int stdfd[3], int fd[2], char *prog, char **args)
strcpy(buf, "exec failed");
write(fd[1], buf, strlen(buf));
close(fd[1]);
+ _threaddebug(DBGSCHED, "_exits in exec-unix");
_exits(buf);
}
|
| diff --git a/src/libthread/id.c b/src/libthread/id.c |
| t@@ -66,6 +66,7 @@ threadsetname(char *fmt, ...)
t->name = vsmprint(fmt, arg);
va_end(arg);
+ _threaddebug(DBGSCHED, "set name %s", t->name);
/* Plan 9 only
if(p->nthreads == 1){
snprint(buf, sizeof buf, "#p/%d/args", getpid()); |
| diff --git a/src/libthread/mkfile b/src/libthread/mkfile |
| t@@ -50,6 +50,9 @@ tprimes: tprimes.$O $PLAN9/lib/$LIB
texec: texec.$O $PLAN9/lib/$LIB
$LD -o texec texec.$O $LDFLAGS -lthread -l9
+tspawn: tspawn.$O $PLAN9/lib/$LIB
+ $LD -o tspawn tspawn.$O $LDFLAGS -lthread -l9
+
trend: trend.$O $PLAN9/lib/$LIB
$LD -o trend trend.$O $LDFLAGS -lthread -l9
|
| diff --git a/src/libthread/note.c b/src/libthread/note.c |
| t@@ -87,9 +87,7 @@ _threadnote(void *v, char *s)
Note *n;
_threaddebug(DBGNOTE, "Got note %s", s);
- if(strncmp(s, "sys:", 4) == 0
- && strcmp(s, "sys: write on closed pipe") != 0
- && strcmp(s, "sys: child") != 0)
+ if(strncmp(s, "sys:", 4) == 0)
noted(NDFLT);
// if(_threadexitsallstatus){ |
| diff --git a/src/libthread/pthread.c b/src/libthread/pthread.c |
| t@@ -60,6 +60,7 @@ _threadinitproc(Proc *p)
void
_threadexitproc(char *exitstr)
{
+ _threaddebug(DBGSCHED, "_pthreadexit");
pthread_exit(nil);
}
t@@ -69,7 +70,8 @@ _threadexitproc(char *exitstr)
void
_threadexitallproc(char *exitstr)
{
- exits(0);
+ _threaddebug(DBGSCHED, "_threadexitallproc");
+ exits(exitstr);
}
/*
t@@ -111,6 +113,7 @@ _threadwaitproc(void *v)
else
free(w);
}
+fprint(2, "_threadwaitproc exits\n");
}
/* |
| diff --git a/src/libthread/sched.c b/src/libthread/sched.c |
| t@@ -170,9 +170,10 @@ runthread(Proc *p)
/*
* Maybe we were awakened to exit?
*/
- if(_threadexitsallstatus)
+ if(_threadexitsallstatus){
+ _threaddebug(DBGSCHED, "time to exit");
_exits(_threadexitsallstatus);
-
+ }
assert(q->head != nil);
}
t@@ -291,9 +292,12 @@ schedexit(Proc *p)
strncpy(ex, p->exitstr, sizeof ex);
ex[sizeof ex-1] = '\0';
free(p);
- if(n == 0)
+ if(n == 0){
+ _threaddebug(DBGSCHED, "procexit; no more procs");
_threadexitallproc(ex);
- else
+ }else{
+ _threaddebug(DBGSCHED, "procexit");
_threadexitproc(ex);
+ }
}
|
| diff --git a/src/libthread/ucontext.c b/src/libthread/ucontext.c |
| t@@ -1,5 +1,12 @@
#include "threadimpl.h"
+static void
+launcher(void (*f)(void*), void *arg)
+{
+ f(arg);
+ threadexits(nil);
+}
+
void
_threadinitstack(Thread *t, void (*f)(void*), void *arg)
{
t@@ -17,7 +24,7 @@ _threadinitstack(Thread *t, void (*f)(void*), void *arg)
/* leave a few words open on both ends */
t->context.uc.uc_stack.ss_sp = t->stk+8;
t->context.uc.uc_stack.ss_size = t->stksize-16;
- makecontext(&t->context.uc, (void(*)())f, 1, arg);
+ makecontext(&t->context.uc, (void(*)())launcher, 2, f, arg);
}
void |