home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Reference Guide / C-C++ Interactive Reference Guide.iso / c_ref / csource5 / 349_01 / sss.arc / EX_0807.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-10  |  2.4 KB  |  133 lines

  1. /* Program EX_0807.C
  2.    Listing 18C - see documentation in TUTOR.SSS
  3. */
  4.  
  5. #include "SSSC.H"
  6.  
  7. #define  ARRIVL  1
  8. #define  STARTA  2
  9. #define  ENDACT  3
  10. #define  NEXTAC  4
  11.  
  12. #define  TIMEL   120
  13.  
  14. #define signal printf("Simulated time %6.2f\x1b[79D",T())
  15.  
  16. int n, countr, server, ecode;
  17. double t0;
  18.  
  19. void prime()
  20. {
  21.   n = 0;
  22.   countr = 0;
  23.   server = 1;
  24.   t0 = 0;
  25.   INIQUE(2, 1, 1);
  26.   INISTA(1, "bus", 1, 0, 0, 0);
  27.   TALLY(1, server);
  28.   CREATE(0, n);
  29. }
  30.  
  31. void resque()
  32. {
  33.   CLEARS(0);
  34.   CLEARQ(0);
  35.   while (NQ(1))
  36.     { REMVFQ(1, 1); DISPOS(); }
  37.   while (NC())
  38.     { REMVFC(1);    DISPOS(); }
  39. }
  40.  
  41. void endper()
  42. {
  43.   switch(countr)
  44.   {
  45.     case 0:
  46.        SETSEE(777);
  47.        SETANT(0);
  48.        break;
  49.  
  50.     case 1:
  51.        printf("# average avail.s duration    \n");
  52.        break;
  53.  
  54.     case 2:
  55.        printf("%1d%8.1f%8.3f%9.2f       \n",
  56.          countr, QAVG(1), SAVG(1), T() - t0);
  57.        break;
  58.  
  59.     case 3:
  60.        printf("%1d%8.1f%8.3f%9.2f       \n",
  61.          countr, QAVG(1), SAVG(1), T() - t0);
  62.        QUEUE(2, 0);
  63.        resque();
  64.        server = 1;
  65.        REMVFQ(2, 1);
  66.        SETSEE(777);
  67.        SETANT(1);
  68.        break;
  69.  
  70.     case 4:
  71.        break;
  72.  
  73.     case 5:
  74.        printf("%1d%8.1f%8.3f%9.2f       \n",
  75.          countr, QAVG(1), SAVG(1), T() - t0);
  76.        break;
  77.  
  78.     case 6:
  79.        printf("%1d%8.1f%8.3f%9.2f       \n",
  80.          countr, QAVG(1), SAVG(1), T() - t0);
  81.        SIMEND(0);
  82.   }
  83.   CLEARS(0);
  84.   CLEARQ(1);
  85.   countr = countr + 1;
  86.   t0 = T();
  87. }
  88.  
  89. main()
  90. {
  91.   prime();
  92.  
  93.   do
  94.   {
  95.     if ((ecode = NEXTEV()) > 0)
  96.     switch(ecode)
  97.     {
  98.  
  99.       case ARRIVL :
  100.               if (n == countr*TIMEL) endper();
  101.               n = n + 1;
  102.               signal;
  103.               SETA(1, EX(0.9));
  104.               CREATE(EX(1), n);
  105.               SCHED(0, NEXTAC, IDE());
  106.               break;
  107.  
  108.       case NEXTAC :
  109.               if (server) SCHED(0, STARTA, IDE());
  110.               else QUEUE(1, 0);
  111.               break;
  112.  
  113.       case STARTA :
  114.               SCHED(A(1), ENDACT, IDE());
  115.               server = server - 1;
  116.               TALLY(1, server);
  117.               break;
  118.  
  119.       case ENDACT :
  120.               DISPOS();
  121.               server = server + 1;
  122.               TALLY(1, server);
  123.               if (NQ(1))
  124.               {
  125.                 REMVFQ(1,1);
  126.                 SCHED(0, STARTA, IDE());
  127.               }
  128.               break;
  129.  
  130.     }
  131.   } while(ecode);
  132. }
  133.