4 #include "threadimpl.h"
6 typedef struct Mainarg Mainarg;
16 static jmp_buf _mainjmp;
17 static void mainlauncher(void*);
18 extern void (*_sysfatal)(char*, va_list);
19 extern void (*__assert)(char*);
24 main(int argc, char **argv)
34 //_threaddebuglevel = (DBGSCHED|DBGCHAN|DBGREND)^~0;
36 _qlockinit(_threadrendezvous);
37 _sysfatal = _threadsysfatal;
38 __assert = _threadassert;
40 if(mainstacksize == 0)
41 mainstacksize = 8*1024;
43 a = _threadmalloc(sizeof *a, 1);
47 p = _newproc(mainlauncher, a, mainstacksize, "threadmain", 0, 0);
49 abort(); /* not reached */
53 mainlauncher(void *arg)
58 threadmain(a->argc, a->argv);
59 threadexits("threadmain");
67 while(*p != ' ' && *p != 0)
79 memset(b, 0, sizeof(b));
80 f = open("/dev/cputime", OREAD|OCEXEC);
83 if(read(f, b, sizeof(b)) <= 0){
109 _threaddebug(DBGEXEC, "_schedexec %s", e->prog);
111 exec(e->prog, e->args);
112 _threaddebug(DBGEXEC, "_schedexec failed: %r");
113 rerrstr(buf, sizeof buf);
115 strcpy(buf, "exec failed");
116 write(e->fd[1], buf, strlen(buf));
121 _schedexec(Execargs *e)
125 flag = (_threadwaitchan == nil) ? RFNOWAIT : 0;
126 switch(pid = rfork(RFREND|RFNOTEG|RFFDG|RFMEM|RFPROC|flag)){
139 switch(pid = rfork(RFPROC|RFMEM|RFNOWAIT|p->rforkflag)){
141 *mainp = p; /* write to stack, so local to proc */
142 longjmp(_mainjmp, 1);
154 lock(&_threadpq.lock);
155 for(l=&_threadpq.head; *l; l=&(*l)->next){
163 unlock(&_threadpq.lock);
165 utfecpy(ex, ex+sizeof ex, p->exitstr);
179 p = _threadgetproc();
182 _threaddebug(DBGEXEC, "_schedexecwait %d", t->ret);
194 if((c = _threadwaitchan) != nil)
199 threadexits("procexec");
217 _threadsetproc(Proc *p)