home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / E / TFF-A32R.LZX / AmigaE3.2a / RkrmSrc / Exec_Library / Tasks / tasklist.e < prev    next >
Encoding:
Text File  |  1996-08-29  |  2.9 KB  |  103 lines

  1. -> tasklist.e - Snapshots and prints the ExecBase task list
  2.  
  3. MODULE 'amigalib/lists',
  4.        'exec/execbase',
  5.        'exec/lists',
  6.        'exec/nodes',
  7.        'exec/tasks'
  8.  
  9. CONST NAMELEN=32
  10.  
  11. -> Use extended structure to hold task information
  12. OBJECT taskNode
  13.   ln:ln
  14.   taskaddress
  15.   sigalloc
  16.   sigwait
  17.   name[NAMELEN]:ARRAY
  18. ENDOBJECT
  19.  
  20. PROC main() HANDLE
  21.   DEF ourtasklist:PTR TO lh, task:PTR TO tc, node:PTR TO taskNode,
  22.       tnode:PTR TO taskNode, rnode, exec:PTR TO execbase
  23.   -> E-Note: get the right type for execbase
  24.   exec:=execbase
  25.  
  26.   -> Allocate memory for out list
  27.   NEW ourtasklist
  28.   -> Initialise list structure (ala newList())
  29.   -> E-Note: so why not use newList()!?!
  30.   newList(ourtasklist)
  31.  
  32.   -> Make sure tasks won't switch lists or go away
  33.   Disable()
  34.  
  35.   -> Snapshot task WAIT list
  36.   snapshot(exec.taskwait, ourtasklist)
  37.  
  38.   -> Snapshot task READY list
  39.   -> E-Note: rnode will be first READY task
  40.   rnode:=snapshot(exec.taskready, ourtasklist)
  41.  
  42.   -> Re-enable interrupts and taskswitching
  43.   Enable()
  44.  
  45.   -> Print now (printing above would have defeated a Forbid or Disable)
  46.   WriteF('Pri Address    SigAlloc   SigWait    Taskname\n')
  47.  
  48.   node:=ourtasklist.head
  49.   WriteF('\nWAITING:\n')
  50.   WHILE tnode:=node.ln.succ
  51.     IF tnode=rnode THEN WriteF('\nREADY:\n')  -> We set rnode above
  52.     WriteF('\z\d[2]  \z$\h[8]  \z$\h[8]  \z$\h[8]  \s\n',
  53.            node.ln.pri, node.taskaddress, node.sigalloc,
  54.            node.sigwait, node.name)
  55.     -> E-Note: ignore the messy clean up - see exception handler
  56.     node:=tnode
  57.   ENDWHILE
  58.  
  59.   -> Say who we are
  60.   WriteF('\nTHIS TASK:\n')
  61.   task:=FindTask(NIL)
  62.   WriteF('\z\d[2]  \z$\h[8]  \z$\h[8]  \z$\h[8]  \s\n',
  63.          task.ln.pri, task, task.sigalloc, task.sigwait, task.ln.name)
  64.  
  65. EXCEPT DO
  66.   IF ourtasklist
  67.     -> E-Note: none of this is necessary, since the program is terminating
  68.     node:=ourtasklist.head
  69.     WHILE tnode:=node.ln.succ
  70.       END node
  71.       node:=tnode
  72.     ENDWHILE
  73.     END ourtasklist
  74.   ENDIF
  75.   SELECT exception
  76.   CASE "MEM";  WriteF('Error: Ran out of memory\n')
  77.   ENDSELECT
  78. ENDPROC
  79.  
  80. -> E-Note: having a separate procedure avoids repeating all this code as well
  81. ->         as localising any exception from NEW 
  82. PROC snapshot(from:PTR TO lh, to:PTR TO lh) HANDLE
  83.   -> E-Note: we are really dealing with "tc" (task) nodes not "ln" nodes
  84.   DEF exectask:PTR TO tc, tnode:PTR TO taskNode, first=NIL
  85.   exectask:=from.head
  86.   WHILE exectask.ln.succ
  87.     NEW tnode
  88.     -> Save task information we want to print
  89.     -> E-Note: copy *safely* to tnode.name
  90.     AstrCopy(tnode.name, exectask.ln.name, NAMELEN)
  91.     tnode.ln.pri:=exectask.ln.pri
  92.     tnode.taskaddress:=exectask
  93.     tnode.sigalloc:=exectask.sigalloc
  94.     tnode.sigwait:=exectask.sigwait
  95.     AddTail(to, tnode)
  96.     IF first=NIL THEN first:=tnode  -> E-Note: first task copied
  97.     exectask:=exectask.ln.succ
  98.   ENDWHILE
  99. EXCEPT DO
  100. ENDPROC first
  101.  
  102. versTag: CHAR 0, '$VER: tasklist 37.2 (31.3.92)', 0
  103.