home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 171.lha / SupLib / qint.doc < prev    next >
Text File  |  1988-04-28  |  5KB  |  133 lines

  1.  
  2.                QINT DOCUMENTATION
  3.  
  4.         Matthew Dillon
  5.  
  6.         dillon@ucbvax.berkeley.edu    ARPA
  7.         ...!ihnp4!ucbvax!dillon    USENET
  8.  
  9. NOTE!!!!!   Lattice Users must replace the 'jsr _geta4' call with the
  10.         appropriate call to retrieve the address register for the
  11.         small data model before compiling!    You might have to make
  12.         other modifications as well (I don't know since I don't
  13.         have Lattice).
  14.  
  15.  
  16. The Calls:
  17.     char oldpri;        range -128 to 127
  18.     char newpri;
  19.     char pri;
  20.     long signum;        0 .. 31
  21.  
  22.     void (*vector)();   function vector returning nothing
  23.     void (*oldvec)();
  24.  
  25.  
  26.     While active Q interrupt vectors exist, the tc_ExceptCode in the
  27.     task structure will be modified.  The old tc_ExceptCode is used if
  28.     an unknown exception occurs (one that is not a Q interrupt).
  29.  
  30.     oldpri = SetQPri(newpri)
  31.  
  32.     Set the task's current Q priority.  Any Q interrupts of lower or
  33.     equal priority that occur will be queued until the priority is
  34.     dropped sufficiently.
  35.  
  36.     The initial task priority is -128 (essentially allowing all Q
  37.     interrupts -127 to 127 to occur).
  38.  
  39.     oldvec = SetQVector(signum, vector, arg, pri)
  40.  
  41.     If vector is non-null, enables the exception at the specified
  42.     priority (-127 to 127).  specified vector is called in a C
  43.     compatible way with one user argument (arg).  Specifying a
  44.     priority of -128 does not make sense because this is the lowest
  45.     allowed priority and the Q interrupt will thus never occur.
  46.  
  47.     If vector is null, the exception and Q interrupt is disabled.
  48.     After the last Q interrupt is removed, tc_ExceptCode is restored
  49.     to its original value.
  50.  
  51.  
  52. BUGS:
  53.     The only bug that I know of is a problem with EXEC.
  54.  
  55.     What is Good:    An exception will not occur while one is Forbid()n
  56.     What is Bad:    If an exception comes in while Forbid()n, it will
  57.             NOT be immediately entered when you Permit().
  58.  
  59.     Whoops.  The exception *will* occur when EXEC next checks its
  60.     signals and exceptions, which occurs on the obvious EXEC library
  61.     calls (SetExcept(), SetSignal(), etc...)  and perhaps Wait().
  62.  
  63.     In most cases you can ignore the problem.
  64.  
  65.  
  66. GENERAL WORKINGS OF Q INTERRUPTS:
  67.  
  68.     If you know how EXEC signals and the 68000 interrupt structure
  69.     works, then you know how Q interrupts work.  Simply replace
  70.     "processor" with "task" and "0-7" with "-128 to 127" for task
  71.     Q interrupt priorities (this is different from the Task's
  72.     scheduler priority).
  73.  
  74.     Q interrupts work just like 68000 interrupts.  If the task is
  75.     currently running at a Q interrupt priority N, only Q interrupts
  76.     of HIGHER priority can occur.  Q interrupts of LOWER OR EQUAL
  77.     priority are queued and will occur as soon as the priority is
  78.     lowered.  Everything occurs in priority order, the highest priority
  79.     pending interrupt is always the one running (or the task's main
  80.     routine if it has the highest priority).
  81.  
  82.     Thus, while a Q interrupt handler is running at some specific
  83.     priority, other Q interrupts at the same priority will wait
  84.     until the first one finishes and then execute in a FIFO fashion.
  85.  
  86. THE INTERRUPT VECTOR ROUTINE:
  87.  
  88.     A specific Q interrupt vector is a C subroutine called with one
  89.     longword argument (that specified when you SetQVector()'d it).
  90.     This works fine with the small model.
  91.  
  92.     The handler runs with all normal EXEC processing enabled, and in
  93.     the context of its task.  It can be viewed almost as a subroutine
  94.     call from the task.  However, you must be careful about the
  95.     reentrancy of certain functions.  STDIO, DOS, and many other
  96.     library calls are not reentrant, and you must use SetQPri() to
  97.     ensure such calls are not interrupted.    NOTE that you CAN mix
  98.     certain calls.    I don't have much info on what combinations work,
  99.     but certainly most library calls that do not depend on being
  100.     called singularly from tasks will work (for example, GetMsg()).
  101.     And, of course, if all your handler does is make some small
  102.     calculations this can interrupt anything.
  103.  
  104.     If you cause an exception (the same exception) from within the
  105.     handler, it will be remembered.  (That is, the signal is cleared
  106.     before the handler is called), and occur after your handler
  107.     returns.
  108.  
  109. USES FOR Q INTERRUPTS:
  110.  
  111.     Use #1:     To be able to execute menu options which do not effect
  112.             the 'current' operation.  E.G. if you are doing a
  113.             ray tracing you could make the intuition window's
  114.             signal bit a Q interrupt and handle Intuition messages
  115.             that way....   The main loop generating the ray
  116.             tracing would not have to continuously check for
  117.             Intuition messages.
  118.  
  119.     Use #2:     Lets say you are writing a terminal program and want
  120.             to display data comming in smoothly while sending a
  121.             file.  While this can be done easily with the
  122.             asynchronous ability of IO devices, it would be even
  123.             easier if you handled the receive with a Q interrupt...
  124.             that way, you could display received data (SendIO to
  125.             the console device) even if the file sender is in
  126.             the middle of a DOS call to read the next file block.
  127.  
  128.     Many more uses (I hope!).
  129.  
  130.                 -Matt
  131.  
  132.  
  133.