Blob
- Date:
- Message:
- 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.
- Actions:
- History | Blame | Raw File
1 #include "threadimpl.h"3 /* this will need work */4 enum5 {6 PTABHASH = 257,7 };9 static int multi;10 static Proc *theproc;12 void13 _threadmultiproc(void)14 {15 if(multi == 0){16 multi = 1;17 _threadsetproc(theproc);18 }19 }21 static Lock ptablock;22 Proc *ptab[PTABHASH];24 void25 _threadsetproc(Proc *p)26 {27 int h;29 if(!multi){30 theproc = p;31 return;32 }33 lock(&ptablock);34 h = ((unsigned)p->pid)%PTABHASH;35 p->link = ptab[h];36 unlock(&ptablock);37 ptab[h] = p;38 }40 static Proc*41 __threadgetproc(int rm)42 {43 Proc **l, *p;44 int h, pid;46 if(!multi)47 return theproc;49 pid = _threadgetpid();51 lock(&ptablock);52 h = ((unsigned)pid)%PTABHASH;53 for(l=&ptab[h]; p=*l; l=&p->link){54 if(p->pid == pid){55 if(rm)56 *l = p->link;57 unlock(&ptablock);58 return p;59 }60 }61 unlock(&ptablock);62 return nil;63 }65 Proc*66 _threadgetproc(void)67 {68 return __threadgetproc(0);69 }71 Proc*72 _threaddelproc(void)73 {74 return __threadgetproc(1);75 }