Various additions and fixes.
This commit is contained in:
parent
74f990ad84
commit
fd04aacee1
57 changed files with 2176 additions and 159 deletions
42
src/lib9/rendez.c
Normal file
42
src/lib9/rendez.c
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
#include <u.h>
|
||||
#include <libc.h>
|
||||
#include "9proc.h"
|
||||
|
||||
static Lock rendlock;
|
||||
static Uproc *rendhash[RENDHASH];
|
||||
|
||||
ulong
|
||||
rendezvous(ulong tag, ulong val)
|
||||
{
|
||||
char c;
|
||||
ulong ret;
|
||||
Uproc *t, *self, **l;
|
||||
|
||||
self = _p9uproc();
|
||||
lock(&rendlock);
|
||||
l = &rendhash[tag%RENDHASH];
|
||||
for(t=*l; t; l=&t->rendhash, t=*l){
|
||||
if(t->rendtag==tag){
|
||||
*l = t->rendhash;
|
||||
ret = t->rendval;
|
||||
t->rendval = val;
|
||||
t->rendtag++;
|
||||
c = 0;
|
||||
unlock(&rendlock);
|
||||
write(t->pipe[1], &c, 1);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
/* Going to sleep here. */
|
||||
t = self;
|
||||
t->rendtag = tag;
|
||||
t->rendval = val;
|
||||
t->rendhash = *l;
|
||||
*l = t;
|
||||
unlock(&rendlock);
|
||||
do
|
||||
read(t->pipe[0], &c, 1);
|
||||
while(t->rendtag == tag);
|
||||
return t->rendval;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue