Blob
1 #include <u.h>2 #include <libc.h>3 #include "9proc.h"5 static Lock rendlock;6 static Uproc *rendhash[RENDHASH];8 ulong9 rendezvous(ulong tag, ulong val)10 {11 char c;12 ulong ret;13 Uproc *t, *self, **l;15 self = _p9uproc(0);16 lock(&rendlock);17 l = &rendhash[tag%RENDHASH];18 for(t=*l; t; l=&t->rendhash, t=*l){19 if(t->rendtag==tag){20 *l = t->rendhash;21 ret = t->rendval;22 t->rendval = val;23 t->rendtag++;24 c = 0;25 unlock(&rendlock);26 write(t->pipe[1], &c, 1);27 return ret;28 }29 }31 /* Going to sleep here. */32 t = self;33 t->rendtag = tag;34 t->rendval = val;35 t->rendhash = *l;36 *l = t;37 unlock(&rendlock);38 do39 read(t->pipe[0], &c, 1);40 while(t->rendtag == tag);41 return t->rendval;42 }