Category : Modula II Source Code
Archive   : TASKING.ZIP
Filename : TASKS.MOD

 
Output of file : TASKS.MOD contained in archive : TASKING.ZIP
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.


  3 Responses to “Category : Modula II Source Code
Archive   : TASKING.ZIP
Filename : TASKS.MOD

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/