home *** CD-ROM | disk | FTP | other *** search
Modula Implementation | 1986-07-22 | 2.3 KB | 81 lines |
- IMPLEMENTATION MODULE Tasks[7]; (* includes timeslices *)
- (*
- Written by Lloyd Miller Apr 86
-
- Warning. This takes over the timer interupt 1CH. Other
- software using this interupt will be locked out for the period
- that a program with this module is running. eg spoolers.
- It should be possible to have this pass the signal along politly but
- I didn't want to complicate it too much right at first.
-
- For some reason, this module has problems running with Borland's
- SideKick.
-
- A similar IOTRANSFER could be used for the PC-AT "busy wait" BIOS interupt.
- Just duplicate the timer routine and change the interupt vector and
- initialize it the same as the timer.
- *)
-
- FROM Devices IMPORT InstallHandler;
- FROM SYSTEM IMPORT
- ADDRESS, ADR, PROCESS, NEWPROCESS, TRANSFER, IOTRANSFER;
- FROM Storage IMPORT ALLOCATE;
-
- TYPE
- prcsptr = POINTER TO process;
- process = RECORD
- realProcess: PROCESS;
- workSpacePtr: ADDRESS;
- next: prcsptr;
- END;
-
- VAR
- curprocess: prcsptr;
-
- PROCEDURE NewTask(prcs: PROC; size: CARDINAL);
- (* add prcs to circular list *)
- VAR
- newp: prcsptr;
- BEGIN
- NEW(newp);
- WITH newp^ DO
- ALLOCATE(workSpacePtr, size);
- NEWPROCESS(prcs, workSpacePtr, size, realProcess);
- next := curprocess^.next;
- END;
- curprocess^.next := newp;
- END NewTask;
-
- PROCEDURE NextTask;
- VAR
- lastp: prcsptr;
- BEGIN
- lastp := curprocess;
- curprocess := curprocess^.next;
- TRANSFER(lastp^.realProcess, curprocess^.realProcess);
- END NextTask;
-
- VAR
- work, timer: PROCESS;
- timerWKSP: ARRAY [1 .. 250] OF CARDINAL; (* 500 byte workspace *)
-
- PROCEDURE timerISR; (* timer interupt service routine *)
- VAR
- nextp: prcsptr;
- BEGIN
- InstallHandler(timer, 1CH);
- LOOP (* forever ?! *)
- IOTRANSFER(timer, work, 1CH); (* bios timer interupt *)
- curprocess^.realProcess := work;
- curprocess := curprocess^.next;
- work := curprocess^.realProcess;
- END; (* loop forever *)
- END timerISR;
-
- BEGIN
- NEW(curprocess);
- curprocess^.next := curprocess; (* link to self *)
- NEWPROCESS(timerISR, ADR(timerWKSP), 500, timer);
- TRANSFER(work, timer);
- END Tasks.
-