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 >
Text File  |  1993-01-05  |  1KB  |  70 lines

  1. // SIM.CPP
  2. #include "sim.hpp"
  3. #include ...
  4.  
  5. extern coroutine* CURRENT;
  6. extern coroutine* MAINC;
  7. process* MAINP=NULL;
  8. chain SQS;
  9.  
  10. void initProcesses(void)
  11. {    if (MAINP == NULL)
  12.     {   MAINP=new process();
  13.         SQS.put(MAINP,0);
  14.         delete MAINC;
  15.         MAINC=CURRENT=(coroutine*)MAINP;
  16.     }
  17. }
  18.  
  19. process* mainProcess(void)
  20. {    return(MAINP); }
  21.  
  22. process* currentProcess(void)
  23. {    return((process *) CURRENT); }
  24.  
  25. float currentTime(void)
  26. {   return( ((process*)CURRENT)->time ); }
  27.  
  28. void hold(float interval)
  29. {    if (interval > 0)
  30.     {   SQS.get(CURRENT);
  31.         ((process *)CURRENT)->time+=interval;
  32.         SQS.put(CURRENT,
  33.         ((process *)CURRENT)->time);
  34.         resume((coroutine*)SQS.first());
  35.     }
  36. }
  37.  
  38. void passivate(void)
  39. {    SQS.get(CURRENT);
  40.     if (SQS.first() == NULL)
  41.         FATAL("Sequence Set is empty");
  42.     resume((coroutine *)SQS.first());
  43. }
  44.  
  45. void activate(process *p,float time)
  46. {    if (p == CURRENT)
  47.         hold(time - currentTime());
  48.     else
  49.     {   SQS.get(p);
  50.         p->time= ((time > currentTime())?
  51.               time : currentTime());
  52.         SQS.put(p,p->time);
  53.     }
  54. }
  55.  
  56. void cancel(process *p)
  57. {    SQS.get(p);
  58.     if (p == CURRENT)
  59.     {   if (SQS.first() == NULL)
  60.         FATAL("Sequence Set is empty");
  61.         resume((coroutine *)SQS.first());
  62.     }
  63. }
  64.  
  65. void process::superMain(void)
  66. {    main();
  67.     passivate();
  68.     FATAL("terminated process activated");}
  69.  
  70.