Blob


1 #include "threadimpl.h"
3 /* this will need work */
4 enum
5 {
6 PTABHASH = 257,
7 };
9 static Lock ptablock;
10 Proc *ptab[PTABHASH];
12 void
13 _threadsetproc(Proc *p)
14 {
15 int h;
17 lock(&ptablock);
18 h = ((unsigned)p->pid)%PTABHASH;
19 p->link = ptab[h];
20 unlock(&ptablock);
21 ptab[h] = p;
22 }
24 static Proc*
25 __threadgetproc(int rm)
26 {
27 Proc **l, *p;
28 int h, pid;
30 pid = _threadgetpid();
32 lock(&ptablock);
33 h = ((unsigned)pid)%PTABHASH;
34 for(l=&ptab[h]; p=*l; l=&p->link){
35 if(p->pid == pid){
36 if(rm)
37 *l = p->link;
38 unlock(&ptablock);
39 return p;
40 }
41 }
42 unlock(&ptablock);
43 return nil;
44 }
46 Proc*
47 _threadgetproc(void)
48 {
49 return __threadgetproc(0);
50 }
52 Proc*
53 _threaddelproc(void)
54 {
55 return __threadgetproc(1);
56 }