aboutsummaryrefslogtreecommitdiff
path: root/src/libthread/channel.c
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2004-02-29 22:10:26 +0000
committerrsc <devnull@localhost>2004-02-29 22:10:26 +0000
commit5a8e63b2f016735364d17866d5e2bcb35d20c78b (patch)
treed5d0ce11e087efaf81c77311bac9d30aed41783d /src/libthread/channel.c
parentd51419bf4397cf13d0c50bf84c125477c6bed307 (diff)
downloadplan9port-5a8e63b2f016735364d17866d5e2bcb35d20c78b.tar.gz
plan9port-5a8e63b2f016735364d17866d5e2bcb35d20c78b.tar.bz2
plan9port-5a8e63b2f016735364d17866d5e2bcb35d20c78b.zip
Fighting the good fight.
Move libfmt, libutf into subdirectories of lib9. Add poll-based socket i/o to libthread, so that we can avoid using multiple procs when possible, thus removing dependence on crappy pthreads implementations. Convert samterm, acme to the single-proc libthread. Bring libcomplete, acme up-to-date w.r.t. Plan 9 distribution.
Diffstat (limited to 'src/libthread/channel.c')
-rw-r--r--src/libthread/channel.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/libthread/channel.c b/src/libthread/channel.c
index d1ec2985..4f642c84 100644
--- a/src/libthread/channel.c
+++ b/src/libthread/channel.c
@@ -65,9 +65,7 @@ chaninit(Channel *c, int elemsize, int elemcnt)
{
if(elemcnt < 0 || elemsize <= 0 || c == nil)
return -1;
- c->f = 0;
- c->n = 0;
- c->freed = 0;
+ memset(c, 0, sizeof *c);
c->e = elemsize;
c->s = elemcnt;
_threaddebug(DBGCHAN, "chaninit %p", c);
@@ -104,13 +102,16 @@ alt(Alt *alts)
* chanlock. Instead, we delay the note until we've dropped
* the lock.
*/
+
+ /*
+ * T might be nil here -- the scheduler sends on threadwaitchan
+ * directly (in non-blocking mode, of course!).
+ */
t = _threadgetproc()->thread;
- if(t->moribund || _threadexitsallstatus)
+ if((t && t->moribund) || _threadexitsallstatus)
yield(); /* won't return */
s = _procsplhi();
lock(&chanlock);
- t->alt = alts;
- t->chan = Chanalt;
/* test whether any channels can proceed */
n = 0;
@@ -125,7 +126,6 @@ alt(Alt *alts)
if(c==nil){
unlock(&chanlock);
_procsplx(s);
- t->chan = Channone;
return -1;
}
if(canexec(xa))
@@ -138,7 +138,6 @@ alt(Alt *alts)
if(xa->op == CHANNOBLK){
unlock(&chanlock);
_procsplx(s);
- t->chan = Channone;
_threadnalt++;
return xa - alts;
}
@@ -159,6 +158,9 @@ _threadnalt++;
* we need to be here.
*/
Again:
+ t->alt = alts;
+ t->chan = Chanalt;
+
unlock(&chanlock);
_procsplx(s);
r = _threadrendezvous((ulong)&c, 0);