home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / pascal / vdl020d.zip / VMULTI.DOC < prev    next >
Text File  |  1993-04-14  |  11KB  |  477 lines

  1. {
  2.  ════════════════════════════════════════════════════════════════════════════
  3.  
  4.  Visionix Process/Procedure/Thread "Multitasking" Unit (VMULTI)
  5.  Copyright 1991,92,93 Visionix
  6.  ALL RIGHTS RESERVED
  7.  
  8.  DOS MultiTasker (non-preemptive).  This unit makes it possible to time-slice
  9.  program tasks, such as the system clock and other user provided procedures.
  10.  Giving the program the ability to have multiple concurrent actions occuring
  11.  all the time.
  12.  
  13.  ────────────────────────────────────────────────────────────────────────────
  14.  
  15.  Revision history in reverse chronological order:
  16.  
  17.  Initials  Date      Comment
  18.  ────────  ────────  ────────────────────────────────────────────────────────
  19.  
  20.  lpg       03/16/93  Added Source Documentation
  21.  
  22.  mep       02/11/93  Cleaned up code for beta release
  23.  
  24.  jrt       02/08/93  Sync with beta 0.12 release
  25.  
  26.  jrt       12/07/92  Sync with beta 0.11 release
  27.  
  28.  jrt       11/21/92  Sync with beta 0.08
  29.  
  30.  jrt       09/01/92  First logged revision.
  31.  
  32.  ════════════════════════════════════════════════════════════════════════════
  33. }
  34.  
  35. Unit VMulti;
  36.  
  37.  
  38. Uses
  39.  
  40.   VTypes,
  41.   DOS;
  42.  
  43. {────────────────────────────────────────────────────────────────────────────}
  44.  
  45. Const
  46.  
  47.   VMS_New       = 1;
  48.   VMS_Do        = 2;
  49.   VMS_Dispose   = 3;
  50.  
  51. Type
  52.  
  53.   TMultiProc = Procedure( Status : BYTE; Var IData : Pointer );
  54.  
  55.   PMultiProcList = ^TMultiProcList;
  56.  
  57.   TMultiProcList = Record
  58.  
  59.     Proc     : TMultiProc; { pointer to procedure                 }
  60.     Interval : LONGINT;    { interval between required processing }
  61.     SPL      : BYTE;       { service processing level:            }
  62.                            {   7=highest priority, 0 = lowest     }
  63.     Name     : ST80;       { process name                         }
  64.     ID       : Pointer;    { process Instance Data                }
  65.     LastCall : LONGINT;    { last call time                       }
  66.     InProc   : BOOLEAN;    { already in procedure?                }
  67.  
  68.     Next     : PMultiProcList;
  69.  
  70.   END;
  71.  
  72.   TMachine = Record
  73.  
  74.     MultiProcListHead : PMultiProcList;
  75.     MultiProcListCurr : PMultiProcList;
  76.     MultiProcListTail : PMultiProcList;
  77.  
  78.   END;
  79.  
  80. {────────────────────────────────────────────────────────────────────────────}
  81.  
  82. Procedure VMultiProcNew(          Prc            : TMultiProc;
  83.                                   Interval       : LONGINT;
  84.                                   SPL            : BYTE;
  85.                                   Name           : TProcName;
  86.                               Var Error          : WORD           );
  87.  
  88. Procedure VMultiProcDispose(      Name           : TProcName      );
  89.  
  90. Procedure VMultiProcSetSPL(       Name           : TProcName      );
  91.  
  92. Procedure VMultiThreadNew(        Prc            : Pointer;
  93.                                   CallInterval   : LONGINT;
  94.                                   StayInterval   : LONGINT;
  95.                                   SPL            : BYTE;
  96.                                   Name           : TProcName;
  97.                                   StackSize      : WORD;
  98.                                   StackPtr       : Pointer        );
  99.  
  100. Procedure VMultiThreadDispose(    Name           : TProcName      );
  101.  
  102. Procedure VMultiThreadSetSPL(     Name           : TProcName      );
  103.  
  104. Procedure VMultiDo(               SPL            : BYTE           );
  105.  
  106. Procedure VMultiSleep(            Duration       : WORD           );
  107.  
  108. Procedure VMultiCriticalBEGIN;
  109.  
  110. Procedure VMultiCriticalEND;
  111.  
  112. Procedure VMultiSetDVSPL(         SPL            : BYTE           );
  113.  
  114. Procedure VMultiSetWinSPL(        SPL            : BYTE           );
  115.  
  116. {────────────────────────────────────────────────────────────────────────────}
  117.  
  118.  
  119. ──────────────────────────────────────────────────────────────────────────────
  120.  
  121.  
  122. [FUNCTION]
  123.  
  124. Procedure VMultiProcNew(          Prc            : TMultiProc;
  125.                                   Interval       : LONGINT;
  126.                                   SPL            : BYTE;
  127.                                   Name           : TProcName;
  128.                               Var Error          : WORD      );
  129.  
  130. [PARAMETERS]
  131.  
  132. Prc         Pointer to Called Procedure
  133. Interval    Time between updates in MilliSeconds
  134. SPL         Service Processing Level  (7=Highest,0=Lowest)
  135. Name        Name of Process Action
  136. Handle      VAR Returned Multi-tasking Process ID Number
  137. Error       VAR Returned Error Code (0=Success)
  138.  
  139. [RETURNS]
  140.  
  141. Function : None
  142. (VAR     : [Handle] Multi-tasking Process ID Number)
  143. (VAR     : [Error] Error Code)
  144.  
  145. [DESCRIPTION]
  146.  
  147. Procedure to all for the submission and identification of Multitasking
  148. processes and their associated procedures.  Returns a process ID number
  149. Allocates a new Multi-Procedure.
  150.  
  151.  Prc                 Pointer to Multi-Procedure.
  152.  
  153.  Interval            Minimum wait between calls, in 100ths of a
  154.                      second.
  155.  
  156.  SPL                 System Priority Level.  How "important"
  157.                      it is that this multi-proc gets called.
  158.                      0 is most important, 10 is least.
  159.  
  160.  Name                Name of the procedure.
  161.  
  162. [SEE-ALSO]
  163.  
  164. [EXAMPLE]
  165.  
  166.  
  167. ──────────────────────────────────────────────────────────────────────────────
  168.  
  169.  
  170. [FUNCTION]
  171.  
  172. Procedure VMultiProcDispose(      Name           : TProcName    );
  173.  
  174. [PARAMETERS]
  175.  
  176. Name        Name of Process to Remove from List
  177.  
  178. [RETURNS]
  179.  
  180. (None)
  181.  
  182. [DESCRIPTION]
  183.  
  184. Removes processes from the Multi-Tasking Processing list.
  185. Disposes of a previously allocated multi-proc.
  186.  
  187.  Name                Name of the procedure to dispose of.
  188.  
  189. [SEE-ALSO]
  190.  
  191. [EXAMPLE]
  192.  
  193.  
  194. ──────────────────────────────────────────────────────────────────────────────
  195.  
  196.  
  197. [FUNCTION]
  198.  
  199. Procedure VMultiProcSetSPL(       Name           : TProcName    );
  200.  
  201. [PARAMETERS]
  202.  
  203. Name        Name of Process to set the SPL Level on
  204.  
  205. [RETURNS]
  206.  
  207. (None)
  208.  
  209. [DESCRIPTION]
  210.  
  211. [SEE-ALSO]
  212.  
  213. [EXAMPLE]
  214.  
  215.  
  216. ──────────────────────────────────────────────────────────────────────────────
  217.  
  218.  
  219. [FUNCTION]
  220.  
  221. Procedure VMultiThreadNew(        Prc            : Pointer;
  222.                                   CallInterval   : LONGINT;
  223.                                   StayInterval   : LONGINT;
  224.                                   SPL            : BYTE;
  225.                                   Name           : TProcName;
  226.                                   StackSize      : WORD;
  227.                                   StackPtr       : Pointer      );
  228.  
  229. [PARAMETERS]
  230.  
  231. Prc          Pointer to New Thread Procedure
  232. CallInterval Time Between updates in Milliseconds
  233. StayInterval Amount of Processing Time to Spend at this Thread
  234. SPL          Service Processing Level (7=Highest,0=Lowest)
  235. Name         Name of Thread Processing Action
  236. StackSize    Amount of Stack to Allocate to this Thread
  237. StackPtr     Pointer to Allocated Stack
  238.  
  239. [RETURNS]
  240.  
  241. (None)
  242.  
  243. [DESCRIPTION]
  244.  
  245. [SEE-ALSO]
  246.  
  247. [EXAMPLE]
  248.  
  249.  
  250. ──────────────────────────────────────────────────────────────────────────────
  251.  
  252.  
  253. [FUNCTION]
  254.  
  255. Procedure VMultiThreadDispose(    Name           : TProcName    );
  256.  
  257. [PARAMETERS]
  258.  
  259. Name        Name of Thread Procedure to Dispose of
  260.  
  261. [RETURNS]
  262.  
  263. (None)
  264.  
  265. [DESCRIPTION]
  266.  
  267. [SEE-ALSO]
  268.  
  269. [EXAMPLE]
  270.  
  271.  
  272. ──────────────────────────────────────────────────────────────────────────────
  273.  
  274.  
  275. [FUNCTION]
  276.  
  277. Procedure VMultiThreadSetSPL(     Name           : TProcName    );
  278.  
  279. [PARAMETERS]
  280.  
  281. Name        Name of Thread Process to Set the SPL Level on
  282.  
  283. [RETURNS]
  284.  
  285. (None)
  286.  
  287. [DESCRIPTION]
  288.  
  289. [SEE-ALSO]
  290.  
  291. [EXAMPLE]
  292.  
  293.  
  294. ──────────────────────────────────────────────────────────────────────────────
  295.  
  296.  
  297. [FUNCTION]
  298.  
  299. Procedure VMultiDo(               SPL            : BYTE         );
  300.  
  301. [PARAMETERS]
  302.  
  303. SPL         Service Processing Level (7=Highest,0=Lowest)
  304.  
  305. [RETURNS]
  306.  
  307. (None)
  308.  
  309. [DESCRIPTION]
  310.  
  311. This is the key function called to update all multitasking functions
  312. that are equal to or greater than the submitted processing level.
  313. Allows multi-procs of a priority <= SPL to run.
  314.  
  315. Calling this function with an SPL of Zero (0) allows ALL Processes
  316. to be executed.  This is considered the Standard action.
  317.  
  318. [SEE-ALSO]
  319.  
  320. [EXAMPLE]
  321.  
  322.  
  323. ──────────────────────────────────────────────────────────────────────────────
  324.  
  325.  
  326. [FUNCTION]
  327.  
  328. Procedure VMultiSleep(            Duration       : WORD         );
  329.  
  330. [PARAMETERS]
  331.  
  332. Duration    Amount of Time to Sleep (in Milliseconds)
  333.  
  334. [RETURNS]
  335.  
  336. (None)
  337.  
  338. [DESCRIPTION]
  339.  
  340. Functional equivalent of TP Delay, however this one allows for all MT
  341. actions to continue during the pause.
  342.  
  343. Sleeps for "duration" milliseconds, allowing multi-procs to run.
  344.  
  345. [SEE-ALSO]
  346.  
  347. [EXAMPLE]
  348.  
  349.  
  350. ──────────────────────────────────────────────────────────────────────────────
  351.  
  352.  
  353. [FUNCTION]
  354.  
  355. Procedure VMultiCriticalBEGIN;
  356.  
  357. [PARAMETERS]
  358.  
  359. (None)
  360.  
  361. [RETURNS]
  362.  
  363. (None)
  364.  
  365. [DESCRIPTION]
  366.  
  367. Begin a critical section.  No multi-procs will run, interrupts will
  368. be disabled, windows ENTER CRITICAL SECTION will be will be called.
  369.  
  370. [SEE-ALSO]
  371.  
  372. [EXAMPLE]
  373.  
  374.  
  375. ──────────────────────────────────────────────────────────────────────────────
  376.  
  377.  
  378. [FUNCTION]
  379.  
  380. Procedure VMultiCriticalEND;
  381.  
  382. [PARAMETERS]
  383.  
  384. (None)
  385.  
  386. [RETURNS]
  387.  
  388. (None)
  389.  
  390. [DESCRIPTION]
  391.  
  392. Ends a critical section.  Multi-proc can run, interrupts will be
  393. enabled, windows EXIT CRITICAL SECTION will be called.
  394.  
  395. [SEE-ALSO]
  396.  
  397. [EXAMPLE]
  398.  
  399.  
  400. ──────────────────────────────────────────────────────────────────────────────
  401.  
  402.  
  403. [FUNCTION]
  404.  
  405. Procedure VMultiSetDVSPL(         SPL            : BYTE         );
  406.  
  407. [PARAMETERS]
  408.  
  409. SPL         Service Processing Level (7=Highest,0=Lowest)
  410.  
  411. [RETURNS]
  412.  
  413. (None)
  414.  
  415. [DESCRIPTION]
  416.  
  417. Sets the System Priority Level for DesqView task switching.
  418. When VMultiDo is called with a priority >= this SPL,
  419. DesqView will be informed that another DV task should run.
  420.  
  421. [SEE-ALSO]
  422.  
  423. [EXAMPLE]
  424.  
  425.  
  426. ──────────────────────────────────────────────────────────────────────────────
  427.  
  428.  
  429. [FUNCTION]
  430.  
  431. Procedure VMultiSetWinSPL(        SPL            : BYTE         );
  432.  
  433. [PARAMETERS]
  434.  
  435. SPL         Service Processing Level (7=Highest,0=Lowest)
  436.  
  437. [RETURNS]
  438.  
  439. (None)
  440.  
  441. [DESCRIPTION]
  442.  
  443. Sets the System Priority Level for Windows task switching.
  444. When VMultiDo is called with a priority >= this SPL,
  445. windows will be informed that another windows task should run.
  446.  
  447. [SEE-ALSO]
  448.  
  449. [EXAMPLE]
  450.  
  451.  
  452. ──────────────────────────────────────────────────────────────────────────────
  453.  
  454.  
  455. [FUNCTION]
  456.  
  457. Procedure VMultiSetOS2SPL(        SPL            : BYTE         );
  458.  
  459. [PARAMETERS]
  460.  
  461. SPL         Service Processing Level (7=Highest,0=Lowest)
  462.  
  463. [RETURNS]
  464.  
  465. (None)
  466.  
  467. [DESCRIPTION]
  468.  
  469. Sets the System Priority Level for OS/2 task switching.
  470. When VMultiDo is called with a priority >= this SPL,
  471. Os/2 will be informed that another windows task should run.
  472.  
  473. [SEE-ALSO]
  474.  
  475. [EXAMPLE]
  476.  
  477.