aboutsummaryrefslogtreecommitdiff
path: root/src/libthread/main.c
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2004-09-23 03:01:36 +0000
committerrsc <devnull@localhost>2004-09-23 03:01:36 +0000
commit7966faa931bfa9cf4ca53dd2d5b6e1eb0f174411 (patch)
treecbf2c9099f0d78c2c26aeea687803d43049db521 /src/libthread/main.c
parentc6687d4591964cb13df87f55ec4770e778a4a55c (diff)
downloadplan9port-7966faa931bfa9cf4ca53dd2d5b6e1eb0f174411.tar.gz
plan9port-7966faa931bfa9cf4ca53dd2d5b6e1eb0f174411.tar.bz2
plan9port-7966faa931bfa9cf4ca53dd2d5b6e1eb0f174411.zip
Continue fighting pthreads.
Clean up thread library a bit too.
Diffstat (limited to 'src/libthread/main.c')
-rw-r--r--src/libthread/main.c152
1 files changed, 48 insertions, 104 deletions
diff --git a/src/libthread/main.c b/src/libthread/main.c
index 8cdd8ca3..83ee177c 100644
--- a/src/libthread/main.c
+++ b/src/libthread/main.c
@@ -1,135 +1,79 @@
-#include <u.h>
-#include <signal.h>
+/*
+ * Thread library.
+ */
+
#include "threadimpl.h"
typedef struct Mainarg Mainarg;
struct Mainarg
{
- int argc;
- char **argv;
+ int argc;
+ char **argv;
};
-int mainstacksize;
-int _threadnotefd;
-int _threadpasserpid;
-static void mainlauncher(void*);
+int mainstacksize;
extern void (*_sysfatal)(char*, va_list);
-void
-_threadstatus(int x)
-{
- USED(x);
- threadstatus();
-}
-
-void
-_threaddie(int x)
-{
- extern char *_threadexitsallstatus;
- USED(x);
-
- if(_threadexitsallstatus)
- _exits(_threadexitsallstatus);
-}
-
-int
-main(int argc, char **argv)
-{
- Mainarg *a;
- Proc *p;
-
-//_threaddebuglevel = (DBGSCHED|DBGCHAN|DBGREND)^~0;
- _systhreadinit();
- _qlockinit(_threadsleep, _threadwakeup);
- _sysfatal = _threadsysfatal;
- notify(_threadnote);
- if(mainstacksize == 0)
- mainstacksize = 32*1024;
-
- a = _threadmalloc(sizeof *a, 1);
- a->argc = argc;
- a->argv = argv;
- p = _newproc(mainlauncher, a, mainstacksize, "threadmain", 0, 0);
- _scheduler(p);
- abort(); /* not reached */
- return 0;
-}
-
static void
mainlauncher(void *arg)
{
Mainarg *a;
a = arg;
+ _threadmaininit();
threadmain(a->argc, a->argv);
threadexits("threadmain");
}
-void
-_threadsignal(void)
-{
-}
-
-void
-_threadsignalpasser(void)
-{
-}
-
int
-_schedfork(Proc *p)
+main(int argc, char **argv)
{
- int pid;
- lock(&p->lock);
- pid = ffork(RFMEM|RFNOWAIT, _scheduler, p);
- p->pid = pid;
- unlock(&p->lock);
- return pid;
-
-}
+ Mainarg a;
+ Proc *p;
-void
-_schedexit(Proc *p)
-{
- char ex[ERRMAX];
- Proc **l;
+ /*
+ * XXX Do daemonize hack here.
+ */
+
+ /*
+ * Instruct QLock et al. to use our scheduling functions
+ * so that they can operate at the thread level.
+ */
+ _qlockinit(_threadsleep, _threadwakeup);
- lock(&_threadpq.lock);
- for(l=&_threadpq.head; *l; l=&(*l)->next){
- if(*l == p){
- *l = p->next;
- if(*l == nil)
- _threadpq.tail = l;
- break;
- }
- }
- _threadprocs--;
- unlock(&_threadpq.lock);
+ /*
+ * Install our own _threadsysfatal which takes down
+ * the whole conglomeration of procs.
+ */
+ _sysfatal = _threadsysfatal;
- strncpy(ex, p->exitstr, sizeof ex);
- ex[sizeof ex-1] = '\0';
- free(p);
- _exits(ex);
-}
+ /*
+ * XXX Install our own jump handler.
+ */
-int
-nrand(int n)
-{
- return random()%n;
-}
+ /*
+ * Install our own signal handlers.
+ */
+ notify(_threadnote);
-void
-_systhreadinit(void)
-{
+ /*
+ * Construct the initial proc running mainlauncher(&a).
+ */
+ if(mainstacksize == 0)
+ mainstacksize = 32*1024;
+ a.argc = argc;
+ a.argv = argv;
+ p = _newproc();
+ _newthread(p, mainlauncher, &a, mainstacksize, "threadmain", 0);
+ _threadscheduler(p);
+ abort(); /* not reached */
+ return 0;
}
+/*
+ * No-op function here so that sched.o drags in main.o.
+ */
void
-threadstats(void)
+_threadlinkmain(void)
{
- extern int _threadnrendez, _threadhighnrendez,
- _threadnalt, _threadhighnentry;
- fprint(2, "*** THREAD LIBRARY STATS ***\n");
- fprint(2, "nrendez %d high simultaneous %d\n",
- _threadnrendez, _threadhighnrendez);
- fprint(2, "nalt %d high simultaneous entry %d\n",
- _threadnalt, _threadhighnentry);
}