home *** CD-ROM | disk | FTP | other *** search
- Unit Tasker;
- {
- Non-Preemptive MultiTasking Unit
- for Turbo Pascal Version 4
-
- Author : Michael Warot - Blue Star Systems
- Date : November 1987
- Purpose : Simple multi-tasking for turbo pascal 4.0
- Version : 1.10
-
- V1.10 August 1988 MAW - Revise code, speed things up a bit.
- Yield went from 2000 uS to 250uS on an AT!
- V1.04 March 1988 MAW - Modify record used to save process, now
- use a pointer instead of 2 words to save
- the stack frame.
- Eliminate redundant variable NextP
- V1.03 March, 1988 MAW - Modify code to save video state for a given
- process. A flag Video_Save toggles this.
- V1.02 March, 1988 MAW - Modify code to support Sleep Function
- Added procedures LOCK and UNLOCK to permit
- use of non-reentrant procedures in programs
- V1.01 January, 1988 MAW - Remove obsolete startup function Init_Tasking.
- Put in some documentation. Clean up code.
- V1.00 November, 1987 MAW - Initial version, simple and crude, but it works.
- }
- {$F+ Force FAR calls - must be on}
- Interface
- Uses
- Crt; { For saving screen status, etc }
-
- Type
- FlagPtr = ^Boolean; { Pointer to a flag }
- Var
- Save_Video : Boolean; { True for cursor saving }
-
- Function Fork:Boolean; { Call this procedure to spawn a new process. The
- procedure will return to your program twice. The
- first time it will be the root process, and will
- return a value of false, the second time it will
- return a value of true }
-
- Procedure Yield; { Call this procedure often in your code. This is the
- heart of the Multi-Tasking, it will return after all
- of the other processes have a crack at it. }
-
- Procedure Sleep(Flag : FlagPtr);
- { Call this procedure with an address of a flag which
- when TRUE, will re-awaken the process. Upon entry
- this procedure will test the value of this flag, and
- if FALSE, will mark the process HIBER.
- This procedure makes a call to YIELD in all cases.
- Note : Don't let all of you processes Sleep, or
- you could put things into a deadlock. }
-
- Procedure Lock(Resource : Byte);
- { This procedure allows the programmer to insure that
- a procedure is not entered twice, it does this by
- having the second call yield until the resource is
- free, using Sleep }
-
- Procedure UnLock(Resource : Byte);
- { This procedure unlocks a resource, allowing it to be
- used by other processes }
-
- Procedure KillProc; { This procedure is intended to be called by a process
- that has done all of it's work. It marks the process
- as one that is 'DEAD' and thus never re-awakens }
-
- Function Child_Process:Boolean;
- { This function returns True if the calling procedure
- is a child process. This test should be used to branch
- into a specific procedure for a given task. }
-
- Procedure SetPriority(P : Integer);
-
- Function ProcessCount:Integer;
-
- Implementation