home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 349_01 / sss.arc / EX_0701.BAS < prev    next >
BASIC Source File  |  1991-04-10  |  3KB  |  124 lines

  1. ' Program EX_0701.BAS
  2. ' Listing 14B - see documentation in TUTOR.SSS
  3.  
  4. const ARRIVL = 1, STARTA = 2, ENDACT = 3, NEXTAC = 4
  5. const ORD1 = 1, ORD2 = 2, DELUX1 = 3, DELUX2 = 4
  6.  
  7. dim shared server(1 to 2)
  8.  
  9. declare sub prime ()
  10. declare sub preemp ()
  11. declare function sindex ()
  12. declare function shortr ()
  13.  
  14. rem $include: 'SSSB.H'
  15.  
  16.   call prime
  17.  
  18.   do
  19.     ecode = NEXTEV
  20.     if ecode > 0 then
  21.       select case ecode
  22.  
  23.       case ARRIVL
  24.                CREATE EX(2), 0
  25.                SETA 1, 0
  26.                SETA 2, TR(1, 2, 3)
  27.                if RA < .25 then
  28.                  SETIDE DELUX1
  29.                else
  30.                  SETIDE ORD1
  31.                end if
  32.                SCHED 0, NEXTAC, IDE
  33.  
  34.       case NEXTAC
  35.                if server(1) > 0 then
  36.                  SCHED 0, STARTA, IDE
  37.                elseif server(2) > 0 then
  38.                  SCHED 0, STARTA, IDE + 1
  39.                elseif IDE = DELUX1 then
  40.                  preemp
  41.                else
  42.                  QUEUE shortr, 0
  43.                end if
  44.  
  45.       case STARTA
  46.                s = sindex
  47.                server(s) = server(s) - 1
  48.                SCHED A(2), ENDACT, IDE
  49.  
  50.       case ENDACT
  51.                s = sindex
  52.                server(s) = server(s) + 1
  53.                if IDE < DELUX1 then TALLY 1, A(1)
  54.                DISPOS
  55.                if NQ(s + 2) > 0 then
  56.                  REMVFQ s + 2, 1
  57.                  SCHED 0, STARTA, IDE
  58.                elseif NQ(s) > 0 then
  59.                  REMVFQ s, 1
  60.                  SCHED 0, STARTA, IDE
  61.                end if
  62.  
  63.       end select
  64.     end if
  65.   loop while ecode > 0
  66.  
  67.   title$ = "  "
  68.   SUMRY sadd(title$)
  69.  
  70. sub preemp
  71.   QUEUE 5, 0
  72.   i = 1
  73.   if NC > 0 then
  74.     for j = 1 to NC
  75.       if IDIC(i) > ORD2 or NEIC(i) <> ENDACT then
  76.         i = i + 1
  77.       end if
  78.     next j
  79.   end if
  80.  
  81.   if i <= NC then
  82.     remt = TIC(i) - t
  83.     REMVFC i
  84.     preide = ide
  85.     SETA 1, A(1) + 1
  86.     SETA 2, remt
  87.  
  88.     title$ = "LIFO   "
  89.     SETQDC 1, sadd(title$)
  90.     QUEUE IDE, 0
  91.     title$ = "FIFO   "
  92.     SETQDC 1, sadd(title$)
  93.     REMVFQ 5, 1
  94.     SCHED 0, STARTA, preide + 2
  95.   else
  96.     REMVFQ 5, 1
  97.     QUEUE shortr, 0
  98.   end if
  99. end sub
  100.  
  101. sub prime
  102.   server(1) = 1
  103.   server(2) = 1
  104.   INIQUE 5, 3, 1
  105.   title$ = "Interrupts            "
  106.   INISTA 1, sadd(title$), 0, 0, 0, 0
  107.   SIMEND 60
  108.   CREATE 0, 0
  109. end sub
  110.  
  111. function shortr
  112.   if NQ(4) + NQ(2) < NQ(3) + NQ(1) then SETIDE IDE + 1
  113.   shortr = IDE
  114. end function
  115.  
  116. function sindex
  117.   if IDE < DELUX1 then
  118.     sindex = IDE
  119.   else
  120.     sindex = IDE - ORD2
  121.   end if
  122. end function
  123.  
  124.