home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
listings
/
v_11_03
/
1103086a
< prev
next >
Wrap
Text File
|
1993-01-05
|
1KB
|
70 lines
// SIM.CPP
#include "sim.hpp"
#include ...
extern coroutine* CURRENT;
extern coroutine* MAINC;
process* MAINP=NULL;
chain SQS;
void initProcesses(void)
{ if (MAINP == NULL)
{ MAINP=new process();
SQS.put(MAINP,0);
delete MAINC;
MAINC=CURRENT=(coroutine*)MAINP;
}
}
process* mainProcess(void)
{ return(MAINP); }
process* currentProcess(void)
{ return((process *) CURRENT); }
float currentTime(void)
{ return( ((process*)CURRENT)->time ); }
void hold(float interval)
{ if (interval > 0)
{ SQS.get(CURRENT);
((process *)CURRENT)->time+=interval;
SQS.put(CURRENT,
((process *)CURRENT)->time);
resume((coroutine*)SQS.first());
}
}
void passivate(void)
{ SQS.get(CURRENT);
if (SQS.first() == NULL)
FATAL("Sequence Set is empty");
resume((coroutine *)SQS.first());
}
void activate(process *p,float time)
{ if (p == CURRENT)
hold(time - currentTime());
else
{ SQS.get(p);
p->time= ((time > currentTime())?
time : currentTime());
SQS.put(p,p->time);
}
}
void cancel(process *p)
{ SQS.get(p);
if (p == CURRENT)
{ if (SQS.first() == NULL)
FATAL("Sequence Set is empty");
resume((coroutine *)SQS.first());
}
}
void process::superMain(void)
{ main();
passivate();
FATAL("terminated process activated");}