[gforth] / gforth / tasker.fs  

gforth: gforth/tasker.fs

Diff for /gforth/tasker.fs between version 1.9 and 1.10

version 1.9, Tue Jun 12 09:29:10 2001 UTC version 1.10, Tue Jun 12 10:49:40 2001 UTC
Line 20 
Line 20 
   
 Create sleepers  sleepers A, sleepers A, 0 ,  Create sleepers  sleepers A, sleepers A, 0 ,
   
 \ LINK-TASK links task1 into the task chain of task2  
 : link-task ( task1 task2 -- )  : link-task ( task1 task2 -- )
       \G LINK-TASK links task1 into the task chain of task2
   over 2@  2dup cell+ ! swap !  \ unlink task1    over 2@  2dup cell+ ! swap !  \ unlink task1
   2dup @ cell+ !  2dup dup @ rot 2!  ! ;    2dup @ cell+ !  2dup dup @ rot 2!  ! ;
   
 : sleep ( task -- )  sleepers  link-task ;  : sleep ( task -- )
 : wake  ( task -- )  next-task link-task ;      \G deactivates task
       sleepers  link-task ;
   : wake  ( task -- )
       \G activates task
       next-task link-task ;
   
 \ PAUSE is the task-switcher  
 : pause ( -- )  : pause ( -- )
       \G PAUSE is the task-switcher
   rp@ fp@ lp@ sp@ save-task !    rp@ fp@ lp@ sp@ save-task !
   next-task @ up! save-task @ sp!    next-task @ up! save-task @ sp!
   lp! fp! rp! ;    lp! fp! rp! ;
   
 \ STOP sleeps a task and switches to the next  
 : stop ( -- )  : stop ( -- )
       \G STOP sleeps a task and switches to the next
   rp@ fp@ lp@ sp@ save-task !    rp@ fp@ lp@ sp@ save-task !
   next-task @ up! save-task @ sp!    next-task @ up! save-task @ sp!
   lp! fp! rp! prev-task @ sleep ;    lp! fp! rp! prev-task @ sleep ;
   
 \ USER' computes the task offset  
 :noname    ' >body @ ;  :noname    ' >body @ ;
 :noname    ' >body @ postpone literal ;  :noname    ' >body @ postpone literal ;
 interpret/compile: user' ( 'user' -- n )  interpret/compile: user' ( 'user' -- n )
   \G USER' computes the task offset of a user variable
   
 \ NEWTASK creates a new, sleeping task  : NewTask ( stacksize -- Task )  dup 2* 2* udp @ + dup
 : NewTask ( n -- Task )  dup 2* 2* udp @ + dup      \G NEWTASK creates a new, sleeping task
   allocate throw  + >r    allocate throw  + >r
   r@ over - udp @ - next-task over udp @ move    r@ over - udp @ - next-task over udp @ move
   r> over user' rp0 + ! dup >r    r> over user' rp0 + ! dup >r
Line 58 
Line 62 
     0 r@ user' current-input + !      0 r@ user' current-input + !
   r> dup 2dup 2! dup sleep ;    r> dup 2dup 2! dup sleep ;
   
 : kill-task  Create killer killer A, killer A,
   : kill ( task -- )
       \G kills a task - deactivate and free task area
       dup killer link-task  killer dup dup 2!
       user' normal-dp + @ free throw ;
   
   : kill-task ( -- )
       \G kills the current task, also on bottom of return stack of a new task
   next-task @ up! save-task @ sp!    next-task @ up! save-task @ sp!
   lp! fp! rp! prev-task @ dup dup link-task user' normal-dp + @ free throw ;      lp! fp! rp! prev-task @ kill ;
   
 : (pass) ( x1 .. xn n task -- )  rdrop  : (pass) ( x1 .. xn n task -- )  rdrop
   [ ' kill-task >body ] ALiteral r>    [ ' kill-task >body ] ALiteral r>
Line 71 
Line 82 
   cells r@ user' sp0 + @ tuck swap - dup r@ user' save-task + !    cells r@ user' sp0 + @ tuck swap - dup r@ user' save-task + !
   ?DO  I !  cell  +LOOP  r> wake ;    ?DO  I !  cell  +LOOP  r> wake ;
   
 : activate ( task -- )  0 swap (pass) ;  : activate ( task -- )
 : pass ( x1 .. xn n task -- )  (pass) ;      \G activates the task.
       \G Continues execution with the caller of ACTIVATE.
       0 swap (pass) ;
   : pass ( x1 .. xn n task -- )
       \G passes n parameters to the task and activates that task.
       \G Continues execution with the caller of PASS.
       (pass) ;
   
 : single-tasking? ( -- flag )  : single-tasking? ( -- flag )
       \G checks if only one task is running
     next-task dup @ = ;      next-task dup @ = ;
   
 : task-key   BEGIN  pause key? single-tasking? or  UNTIL  (key) ;  : task-key   BEGIN  pause key? single-tasking? or  UNTIL  (key) ;


Generate output suitable for use with a patch program
Legend:
Removed from v.1.9  
changed lines
  Added in v.1.10

CVS Admin

Powered by ViewCVS 1.0-dev
(Powered by ViewCVS)

ViewCVS and CVS Help