home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / drdobbs / 1988 / 02 / lindley / lindley.ls4 < prev    next >
Text File  |  1979-12-31  |  3KB  |  88 lines

  1.  
  2. Listing Four: Changes to the multitasking kernel
  3.  
  4. CONST
  5.   task_stack_size = 1000;
  6. PROCEDURE Yield;
  7. {This version in assembly language for}
  8. {speed. See original version for comments.}
  9. BEGIN
  10.    IF cp^.link <> cp THEN  {must have more than}
  11.                            {one task forked to be}
  12.                            {able to yield}
  13.    BEGIN
  14.       INLINE($C6/$06/child_process/$00/
  15.                               {child_process is false}
  16.              $C4/$3E/cp/      {les di,[cp]}
  17.              $89/$E0/         {mov ax,sp}
  18.              $05/$02/$00/     {add ax,2}
  19.              $26/             {es:}
  20.              $89/$45/$04/     {mov [di+4],ax}
  21.              $26/             {es:}
  22.              $C6/$45/$06/$00/ {mov byte ptr [di+6],0}
  23.              $89/$FB/         {L1: mov bx,di}
  24.              $26/             {es:}
  25.              $C4/$1F/         {les bx,[bx]}
  26.              $26/             {es:}
  27.              $80/$7F/$06/$00/ {cmp byte ptr [bx+6],0}
  28.              $74/$04/         {je L2}
  29.              $89/$DF/         {mov di,bx}
  30.              $EB/$F0/         {jmp L1}
  31.              $89/$1E/cp/      {L2: mov [cp],bx}
  32.              $8C/$06/cp+2/    {    mov [cp+2],es}
  33.              $26/             {es:}
  34.              $C6/$47/$06/$02/ {mov byte ptr [bx+6],2}
  35.              $26/             {es:}
  36.              $8B/$6F/$04);    {mov bp,[bx+4]}
  37.    END
  38.    ELSE
  39.    BEGIN
  40.       writeln('Cannot yield only single task running');
  41.       halt;
  42.    END;
  43. END;
  44.  
  45. PROCEDURE Wait;  {put current task in wait mode}
  46.                  {until a send makes it ready}
  47. BEGIN
  48.    IF cp^.link <> cp THEN  {must have more than}
  49.                            {one task forked to be}
  50.                            {able to wait}
  51.    BEGIN
  52.       waitfor^ := cp;      {waitfor points at the}
  53.                            {current task}
  54.       INLINE($C6/$06/child_process/$00/
  55.                               {child_process is false}
  56.              $C4/$3E/cp/      {les di,[cp]}
  57.              $89/$E0/         {mov ax,sp}
  58.              $05/$02/$00/     {add ax,2}
  59.              $26/             {es:}
  60.              $89/$45/$04/     {mov [di+4],ax}
  61.              $26/             {es:}
  62.              $C6/$45/$06/$01/ {mov byte ptr [di+6],1}
  63.              $89/$FB/         {L1: mov bx,di}
  64.              $26/             {es:}
  65.              $C4/$1F/         {les bx,[bx]}
  66.              $26/             {es:}
  67.              $80/$7F/$06/$00/ {cmp byte ptr [bx+6],0}
  68.              $74/$04/         {je L2}
  69.              $89/$DF/         {mov di,bx}
  70.              $EB/$F0/         {jmp L1}
  71.              $89/$1E/cp/      {L2: mov [cp],bx}
  72.              $8C/$06/cp+2/    {    mov [cp+2],es}
  73.              $26/             {es:}
  74.              $C6/$47/$06/$02/ {mov byte ptr [bx+6],2}
  75.              $26/             {es:}
  76.              $8B/$6F/$04);    {mov bp,[bx+4]}
  77.    END
  78.    ELSE
  79.    BEGIN
  80.       writeln('Cannot wait only single task running');
  81.       halt;
  82.    END;
  83. END;
  84.  
  85.  
  86.  
  87.  
  88.