aboutsummaryrefslogtreecommitdiff
path: root/src/libthread
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2004-09-17 03:34:32 +0000
committerrsc <devnull@localhost>2004-09-17 03:34:32 +0000
commitbcf527a98e295548629620a7cb06ada951db7822 (patch)
tree0c459268d6391745a7acc3fefb82ba1e62ed858e /src/libthread
parent06bb4ed20d855b60e39c1125d8d715ba8892265b (diff)
downloadplan9port-bcf527a98e295548629620a7cb06ada951db7822.tar.gz
plan9port-bcf527a98e295548629620a7cb06ada951db7822.tar.bz2
plan9port-bcf527a98e295548629620a7cb06ada951db7822.zip
Continue switching library over to pthreads when possible.
Tprimes works on Linux 2.6. You can only have 128 procs though.
Diffstat (limited to 'src/libthread')
-rw-r--r--src/libthread/channel.c6
-rw-r--r--src/libthread/main.c4
-rw-r--r--src/libthread/mkfile3
-rw-r--r--src/libthread/sched.c28
-rw-r--r--src/libthread/threadimpl.h4
-rw-r--r--src/libthread/tprimes.c1
6 files changed, 19 insertions, 27 deletions
diff --git a/src/libthread/channel.c b/src/libthread/channel.c
index cdb8376e..14791d05 100644
--- a/src/libthread/channel.c
+++ b/src/libthread/channel.c
@@ -29,7 +29,7 @@ canexec(Alt *a)
/* are there senders or receivers blocked? */
otherop = (CHANSND+CHANRCV) - a->op;
for(i=0; i<c->nentry; i++)
- if(c->qentry[i] && c->qentry[i]->op==otherop && c->qentry[i]->thread==nil){
+ if(c->qentry[i] && c->qentry[i]->op==otherop && c->qentry[i]->thread->altc==nil){
_threaddebug(DBGCHAN, "can rendez alt %p chan %p", a, c);
return 1;
}
@@ -460,7 +460,7 @@ altexec(Alt *a, int spl)
b = nil;
me = a->v;
for(i=0; i<c->nentry; i++)
- if(c->qentry[i] && c->qentry[i]->op==otherop && c->qentry[i]->thread==nil)
+ if(c->qentry[i] && c->qentry[i]->op==otherop && c->qentry[i]->thread->altc==nil)
if(nrand(++n) == 0)
b = c->qentry[i];
if(b != nil){
@@ -488,7 +488,7 @@ altexec(Alt *a, int spl)
altcopy(waiter, me, c->e);
}
b->thread->altc = c;
- _procwakeup(&b->thread->altrend);
+ _threadwakeup(&b->thread->altrend);
_threaddebug(DBGCHAN, "chanlock is %lud", *(ulong*)(void*)&chanlock);
_threaddebug(DBGCHAN, "unlocking the chanlock");
unlock(&chanlock);
diff --git a/src/libthread/main.c b/src/libthread/main.c
index 6129f3e0..679a334b 100644
--- a/src/libthread/main.c
+++ b/src/libthread/main.c
@@ -49,9 +49,7 @@ main(int argc, char **argv)
a = _threadmalloc(sizeof *a, 1);
a->argc = argc;
a->argv = argv;
-malloc(10);
p = _newproc(mainlauncher, a, mainstacksize, "threadmain", 0, 0);
-malloc(10);
_schedinit(p);
abort(); /* not reached */
return 0;
@@ -62,9 +60,7 @@ mainlauncher(void *arg)
{
Mainarg *a;
-malloc(10);
a = arg;
-malloc(10);
threadmain(a->argc, a->argv);
threadexits("threadmain");
}
diff --git a/src/libthread/mkfile b/src/libthread/mkfile
index d1a095e7..abff1629 100644
--- a/src/libthread/mkfile
+++ b/src/libthread/mkfile
@@ -41,6 +41,9 @@ HFILES=\
<$PLAN9/src/mksyslib
+tfork: tfork.$O $PLAN9/lib/$LIB
+ $LD -o tfork tfork.$O $LDFLAGS -lthread -l9
+
tprimes: tprimes.$O $PLAN9/lib/$LIB
$LD -o tprimes tprimes.$O $LDFLAGS -lthread -l9
diff --git a/src/libthread/sched.c b/src/libthread/sched.c
index f9e680fd..60a8854b 100644
--- a/src/libthread/sched.c
+++ b/src/libthread/sched.c
@@ -36,7 +36,6 @@ _schedinit(void *arg)
unlock(&p->lock);
while(_setlabel(&p->sched))
;
-malloc(10);
_threaddebug(DBGSCHED, "top of schedinit, _threadexitsallstatus=%p", _threadexitsallstatus);
if(_threadexitsallstatus)
_exits(_threadexitsallstatus);
@@ -148,12 +147,10 @@ relock:
_threaddebug(DBGSCHED, "sleeping for more work (%d threads)", p->nthreads);
q->asleep = 1;
- unlock(&p->readylock);
- while(rendezvous((ulong)q, 0) == ~0){
- if(_threadexitsallstatus)
- _exits(_threadexitsallstatus);
- }
- /* lock picked up from _threadready */
+ p->rend.l = &p->readylock;
+ _procsleep(&p->rend);
+ if(_threadexitsallstatus)
+ _exits(_threadexitsallstatus);
}
t = q->head;
q->head = t->next;
@@ -185,18 +182,15 @@ _sched(void)
Resched:
p = _threadgetproc();
//fprint(2, "p %p\n", p);
-malloc(10);
if((t = p->thread) != nil){
needstack(512);
// _threaddebug(DBGSCHED, "pausing, state=%s set %p goto %p",
// psstate(t->state), &t->sched, &p->sched);
-print("swap\n");
if(_setlabel(&t->sched)==0)
_gotolabel(&p->sched);
_threadstacklimit(t->stk, t->stk+t->stksize);
return p->nsched++;
}else{
-malloc(10);
t = runthread(p);
if(t == nil){
_threaddebug(DBGSCHED, "all threads gone; exiting");
@@ -211,8 +205,6 @@ malloc(10);
}
t->state = Running;
t->nextstate = Ready;
-malloc(10);
-print("gotolabel\n");
_gotolabel(&t->sched);
for(;;);
}
@@ -253,13 +245,11 @@ _threadready(Thread *t)
assert(q->asleep == 1);
q->asleep = 0;
/* lock passes to runthread */
- _threaddebug(DBGSCHED, "waking process %d", t->proc->pid);
- while(rendezvous((ulong)q, 0) == ~0){
- if(_threadexitsallstatus)
- _exits(_threadexitsallstatus);
- }
- }else
- unlock(&t->proc->readylock);
+ _procwakeup(&t->proc->rend);
+ }
+ unlock(&t->proc->readylock);
+ if(_threadexitsallstatus)
+ _exits(_threadexitsallstatus);
}
void
diff --git a/src/libthread/threadimpl.h b/src/libthread/threadimpl.h
index 851186e3..d6a23905 100644
--- a/src/libthread/threadimpl.h
+++ b/src/libthread/threadimpl.h
@@ -95,6 +95,8 @@ struct Thread
Chanstate chan; /* which channel operation is current */
Alt *alt; /* pointer to current alt structure (debugging) */
ulong userpc;
+ Channel *c;
+ pthread_cond_t cond;
void* udata[NPRIV]; /* User per-thread data pointer */
int lastfd;
@@ -136,6 +138,8 @@ struct Proc
uint nextID; /* ID of most recently created thread */
Proc *next; /* linked list of Procs */
+ _Procrend rend; /* sleep here for more ready threads */
+
void *arg; /* passed between shared and unshared stk */
char str[ERRMAX]; /* used by threadexits to avoid malloc */
char errbuf[ERRMAX]; /* errstr */
diff --git a/src/libthread/tprimes.c b/src/libthread/tprimes.c
index 0e719451..89d30c03 100644
--- a/src/libthread/tprimes.c
+++ b/src/libthread/tprimes.c
@@ -41,7 +41,6 @@ threadmain(int argc, char **argv)
int i;
Channel *c;
-malloc(10);
ARGBEGIN{
case 'D':
_threaddebuglevel = atoi(ARGF());