diff options
author | Taru Karttunen <taruti@taruti.net> | 2011-03-30 15:46:40 +0300 |
---|---|---|
committer | Taru Karttunen <taruti@taruti.net> | 2011-03-30 15:46:40 +0300 |
commit | e5888a1ffdae813d7575f5fb02275c6bb07e5199 (patch) | |
tree | d8d51eac403f07814b9e936eed0c9a79195e2450 /sys/src/libthread/exit.c |
Import sources from 2011-03-30 iso image
Diffstat (limited to 'sys/src/libthread/exit.c')
-rwxr-xr-x | sys/src/libthread/exit.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/sys/src/libthread/exit.c b/sys/src/libthread/exit.c new file mode 100755 index 000000000..d36e11af4 --- /dev/null +++ b/sys/src/libthread/exit.c @@ -0,0 +1,72 @@ +#include <u.h> +#include <libc.h> +#include <thread.h> +#include "threadimpl.h" +#include <tos.h> + +char *_threadexitsallstatus; +Channel *_threadwaitchan; + +void +threadexits(char *exitstr) +{ + Proc *p; + Thread *t; + + p = _threadgetproc(); + t = p->thread; + t->moribund = 1; + if(exitstr==nil) + exitstr=""; + utfecpy(p->exitstr, p->exitstr+ERRMAX, exitstr); + _sched(); +} + +void +threadexitsall(char *exitstr) +{ + Proc *p; + int pid[64]; + int i, npid, mypid; + + if(exitstr == nil) + exitstr = ""; + _threadexitsallstatus = exitstr; + _threaddebug(DBGSCHED, "_threadexitsallstatus set to %p", _threadexitsallstatus); + mypid = _tos->pid; //getpid(); + + /* + * signal others. + * copying all the pids first avoids other threads + * teardown procedures getting in the way. + * + * avoid mallocs since malloc can post a note which can + * call threadexitsall... + */ + for(;;){ + lock(&_threadpq.lock); + npid = 0; + for(p = _threadpq.head; p && npid < nelem(pid); p=p->next){ + if(p->threadint == 0 && p->pid != mypid){ + pid[npid++] = p->pid; + p->threadint = 1; + } + } + unlock(&_threadpq.lock); + if(npid == 0) + break; + for(i=0; i<npid; i++) + postnote(PNPROC, pid[i], "threadint"); + } + + /* leave */ + exits(exitstr); +} + +Channel* +threadwaitchan(void) +{ + if(_threadwaitchan==nil) + _threadwaitchan = chancreate(sizeof(Waitmsg*), 16); + return _threadwaitchan; +} |