home *** CD-ROM | disk | FTP | other *** search
/ Boston 2 / boston-2.iso / DOS / PROGRAM / MODULA / FSTCOMPI / KERNEL.DEF < prev    next >
Text File  |  1993-12-01  |  4KB  |  111 lines

  1. DEFINITION MODULE Kernel;
  2.  
  3. (* (C) Copyright 1987 Fitted Software Tools. All rights reserved.
  4.  
  5.     This module is part of the example multitasking communications program
  6.     provided with the Fitted Software Tools' Modula-2 development system.
  7.  
  8.     Registered users may use this program as is, or they may modify it to
  9.     suit their needs or as an exercise.
  10.  
  11.     If you develop interesting derivatives of this program and would like
  12.     to share it with others, we encourage you to upload a copy to our BBS.
  13. *)
  14.  
  15. (*
  16.     This is the multitasking kernel.
  17.  
  18.     The terms process and task are used interchangeably throughout...
  19.  
  20.     The kernel contains a scheduler that dispatches the CPU to the next
  21.     available "ready to run" task whenever some task makes a request that
  22.     prevents it from continuing running.
  23.  
  24.     Tasks may be suspended for one of three reasons:
  25.         1-  when issuing a WaitIO, until the interrupt occurs.
  26.         2-  when issuing a Lock on a LockHeader already locked by another
  27.             task.
  28.         3-  when issuing a Wait, if no signals are pending on that
  29.             particular SignalHeader.
  30.  
  31.     Resuming tasks:
  32.         1-  If a task is waiting on an IO and the interrupt occurs, this
  33.             task preempts the currently executing one.
  34.         2-  If a task is suspended on a LockHeaderm it is made "ready to
  35.             run" when the LockHeader is unlocked.
  36.         3-  If a task is suspended on a SignalHeader, it is made "ready
  37.             to run" when a Signal is sent to this SignalHeader.
  38.  
  39.     A task that is in a "ready to run" state, is resumed when the tasks
  40.     ahead of it in the ready list get removed (suspended).
  41.  
  42.     The kernel provides an idle process that runs whenever nothing else
  43.     can. This idle process simply loops.
  44. *)
  45.  
  46. FROM SYSTEM IMPORT ADDRESS;
  47.  
  48. TYPE
  49.     SignalHeader;
  50.     LockHeader;
  51.  
  52. PROCEDURE NewProcess( p :PROC; n :CARDINAL; iop :BOOLEAN );
  53. (*
  54.     Creates a new process structure and places it in the ready list.
  55.     The process is not started.
  56.  
  57.     p is the main procedure for the process.
  58.  
  59.     n is the size of the stack to allocate for the process.
  60.  
  61.     iop should be TRUE if this is an I/O process -- I/O processes are
  62.     higher priority than the other processes.
  63. *)
  64.  
  65. PROCEDURE InitSignal( VAR s :SignalHeader );
  66. (*
  67.     Initialize the signal header.
  68.     Must be invoked before a Signal or Wait is done on this header.
  69. *)
  70.  
  71. PROCEDURE Signal( VAR s :SignalHeader );
  72. (*
  73.     Send a signal to the signal header.
  74.     If a process is Waiting on theis header, it is made "ready",
  75.     otherwise the signal count is incremented.
  76. *)
  77.  
  78. PROCEDURE Wait( VAR s :SignalHeader );
  79. (*
  80.     If the signal count in this signal header is not 0, it is decremented
  81.     and the process continues; otherwise, the process is suspended.
  82. *)
  83.  
  84. PROCEDURE InitLock( VAR l :LockHeader );
  85. (*
  86.     Initialize the lock header.
  87.     Must be invoked before a Lock or Unlock is done on this header.
  88. *)
  89.  
  90. PROCEDURE Lock( VAR l :LockHeader );
  91. (*
  92.     If this header is free (or already locked by the current process)
  93.     give the lock to this process. In this case, the process continues
  94.     running.
  95.  
  96.     If this header is locked by another process, suspend.
  97. *)
  98.  
  99. PROCEDURE Unlock( VAR l :LockHeader );
  100. (*
  101.     If the calling process owns this lock header, the lock is freed up;
  102.     If there was a process suspended on this lock header, that process
  103.     is made "ready" and given the lock.
  104. *)
  105.  
  106. PROCEDURE WaitIO( v :CARDINAL );
  107. (*
  108.     Suspend the current process until an interrupt occurs on vector v.
  109. *)
  110.  
  111. END Kernel.