2003-09-30 17:47:42 +00:00
|
|
|
#include "threadimpl.h"
|
|
|
|
|
|
|
|
/* this will need work */
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PTABHASH = 257,
|
|
|
|
};
|
|
|
|
|
2004-02-29 22:10:26 +00:00
|
|
|
static int multi;
|
|
|
|
static Proc *theproc;
|
|
|
|
|
|
|
|
void
|
|
|
|
_threadmultiproc(void)
|
|
|
|
{
|
|
|
|
if(multi == 0){
|
|
|
|
multi = 1;
|
|
|
|
_threadsetproc(theproc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-30 17:47:42 +00:00
|
|
|
static Lock ptablock;
|
|
|
|
Proc *ptab[PTABHASH];
|
|
|
|
|
|
|
|
void
|
|
|
|
_threadsetproc(Proc *p)
|
|
|
|
{
|
|
|
|
int h;
|
|
|
|
|
2004-02-29 22:10:26 +00:00
|
|
|
if(!multi){
|
|
|
|
theproc = p;
|
|
|
|
return;
|
|
|
|
}
|
2003-09-30 17:47:42 +00:00
|
|
|
lock(&ptablock);
|
|
|
|
h = ((unsigned)p->pid)%PTABHASH;
|
|
|
|
p->link = ptab[h];
|
|
|
|
unlock(&ptablock);
|
|
|
|
ptab[h] = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Proc*
|
|
|
|
__threadgetproc(int rm)
|
|
|
|
{
|
|
|
|
Proc **l, *p;
|
|
|
|
int h, pid;
|
|
|
|
|
2004-02-29 22:10:26 +00:00
|
|
|
if(!multi)
|
|
|
|
return theproc;
|
|
|
|
|
2003-09-30 17:47:42 +00:00
|
|
|
pid = _threadgetpid();
|
|
|
|
|
|
|
|
lock(&ptablock);
|
|
|
|
h = ((unsigned)pid)%PTABHASH;
|
|
|
|
for(l=&ptab[h]; p=*l; l=&p->link){
|
|
|
|
if(p->pid == pid){
|
|
|
|
if(rm)
|
|
|
|
*l = p->link;
|
|
|
|
unlock(&ptablock);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unlock(&ptablock);
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
Proc*
|
|
|
|
_threadgetproc(void)
|
|
|
|
{
|
|
|
|
return __threadgetproc(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
Proc*
|
|
|
|
_threaddelproc(void)
|
|
|
|
{
|
|
|
|
return __threadgetproc(1);
|
|
|
|
}
|