summaryrefslogtreecommitdiff
path: root/sys/src/libthread/main.c
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2021-10-13 17:08:26 +0000
committercinap_lenrek <cinap_lenrek@felloff.net>2021-10-13 17:08:26 +0000
commit5a807265a819206f8342ab3a23b940a0c75049fc (patch)
treea84effb4eb8852b1346259b98772c5c269f91e09 /sys/src/libthread/main.c
parent3fe3e370e3bcad21b61aec6cbf5d11a9398e805b (diff)
libthread: fix debug prints, simplify
Do the debuglevel check before calling the print function for _threaddebug, by making it a macro. Do not waste cycles passing arguments. Generalize the _threaddebug function into _threadprint() and add a varargcheck pragma. This function can also be used from _threadassert(). Fix missing arguments in one case, fix trailing newlines in _threaddebug(). Make _threadgetproc()/_threadsetproc() a macro, just dereferencing Proc**_threadprocp. Simplify the mainjump, just call _threadsetproc() directly without that mainp dance. Remove the _schedinit() argument, it uses _threadgetproc() now. Get rid of Mainarg struct, just have a global variable for argc.
Diffstat (limited to 'sys/src/libthread/main.c')
-rw-r--r--sys/src/libthread/main.c74
1 files changed, 18 insertions, 56 deletions
diff --git a/sys/src/libthread/main.c b/sys/src/libthread/main.c
index faa08bf79..7f88c17bc 100644
--- a/sys/src/libthread/main.c
+++ b/sys/src/libthread/main.c
@@ -3,60 +3,42 @@
#include <thread.h>
#include "threadimpl.h"
-typedef struct Mainarg Mainarg;
-struct Mainarg
-{
- int argc;
- char **argv;
-};
-
-int mainstacksize;
-static jmp_buf _mainjmp;
-static void mainlauncher(void*);
extern void (*_sysfatal)(char*, va_list);
extern void (*__assert)(char*);
-static Proc **mainp;
+int mainstacksize;
+
+static jmp_buf mainjmp;
+static int mainargc;
+
+static void
+mainlauncher(void *arg)
+{
+ threadmain(mainargc, arg);
+ threadexits("threadmain");
+}
void
main(int argc, char **argv)
{
- Mainarg *a;
- Proc *p;
-
rfork(RFREND);
- mainp = &p;
//_threaddebuglevel = (DBGSCHED|DBGCHAN|DBGREND)^~0;
- _systhreadinit();
+ _threadprocp = privalloc();
_qlockinit(_threadrendezvous);
_sysfatal = _threadsysfatal;
__assert = _threadassert;
notify(_threadnote);
if(mainstacksize == 0)
mainstacksize = 8*1024;
-
- a = _threadmalloc(sizeof *a, 1);
- a->argc = argc;
- a->argv = argv;
-
- p = _newproc(mainlauncher, a, mainstacksize, "threadmain", 0, 0);
- setjmp(_mainjmp);
- _schedinit(p);
+ mainargc = argc;
+ _threadsetproc(_newproc(mainlauncher, argv, mainstacksize, "threadmain", 0, 0));
+ setjmp(mainjmp);
+ _schedinit();
abort(); /* not reached */
}
static void
-mainlauncher(void *arg)
-{
- Mainarg *a;
-
- a = arg;
- threadmain(a->argc, a->argv);
- threadexits("threadmain");
-}
-
-static void
efork(Execargs *e)
{
char buf[ERRMAX];
@@ -93,8 +75,8 @@ _schedfork(Proc *p)
switch(pid = rfork(RFPROC|RFMEM|RFNOWAIT|p->rforkflag)){
case 0:
- *mainp = p; /* write to stack, so local to proc */
- longjmp(_mainjmp, 1);
+ _threadsetproc(p);
+ longjmp(mainjmp, 1);
default:
return pid;
}
@@ -141,23 +123,3 @@ _schedexecwait(void)
}
threadexits("procexec");
}
-
-static Proc **procp;
-
-void
-_systhreadinit(void)
-{
- procp = privalloc();
-}
-
-Proc*
-_threadgetproc(void)
-{
- return *procp;
-}
-
-void
-_threadsetproc(Proc *p)
-{
- *procp = p;
-}