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;
29 Thread *t;
30 ulong *s;
32 s = (ulong*)((ulong)&pid & ~(STKSIZE-1));
33 if(s[0] == STKMAGIC){
34 t = (Thread*)s[1];
35 return t->proc;
36 }
38 pid = _threadgetpid();
40 lock(&ptablock);
41 h = ((unsigned)pid)%PTABHASH;
42 for(l=&ptab[h]; p=*l; l=&p->link){
43 if(p->pid == pid){
44 if(rm)
45 *l = p->link;
46 unlock(&ptablock);
47 return p;
48 }
49 }
50 unlock(&ptablock);
51 return nil;
52 }
54 Proc*
55 _threadgetproc(void)
56 {
57 return __threadgetproc(0);
58 }
60 Proc*
61 _threaddelproc(void)
62 {
63 return __threadgetproc(1);
64 }