home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / rom / exec / remtask.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-09  |  2.3 KB  |  116 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: remtask.c,v 1.8 1997/01/01 03:46:15 ldp Exp $
  4.  
  5.     Desc:
  6.     Lang: english
  7. */
  8. #include <exec/execbase.h>
  9. #include <exec/tasks.h>
  10. #include <aros/libcall.h>
  11. #include <proto/exec.h>
  12.  
  13. #include "exec_debug.h"
  14. #ifndef DEBUG_RemTask
  15. #   define DEBUG_RemTask 0
  16. #endif
  17. #if DEBUG_RemTask
  18. #   undef DEBUG
  19. #   define DEBUG 1
  20. #endif
  21. #include <aros/debug.h>
  22.  
  23. /*****************************************************************************
  24.  
  25.     NAME */
  26.  
  27.     AROS_LH1(void, RemTask,
  28.  
  29. /*  SYNOPSIS */
  30.     AROS_LHA(struct Task *,     task, A1),
  31.  
  32. /*  LOCATION */
  33.     struct ExecBase *, SysBase, 48, Exec)
  34.  
  35. /*  FUNCTION
  36.     Remove a task from the task lists. All memory in the tc_MemEntry list
  37.     is freed and a rescedule is done. It's safe to call RemTask() out
  38.     of Forbid() or Disable().
  39.     This function is one way to get rid of the current task. The other way
  40.     is to fall through the end of the entry point.
  41.  
  42.     INPUTS
  43.     task - Task to be removed. NULL means current task.
  44.  
  45.     RESULT
  46.  
  47.     NOTES
  48.  
  49.     EXAMPLE
  50.  
  51.     BUGS
  52.  
  53.     SEE ALSO
  54.     AddTask()
  55.  
  56.     INTERNALS
  57.  
  58.     HISTORY
  59.  
  60. ******************************************************************************/
  61. {
  62.     AROS_LIBFUNC_INIT
  63.     struct MemList *mb;
  64.  
  65.     /* A value of NULL means current task */
  66.     if (task==NULL)
  67.     task=SysBase->ThisTask;
  68.  
  69.     D(bug("Call RemTask (%08lx (\"%s\"))\n", task, task->tc_Node.ln_Name));
  70.  
  71.     /*
  72.     Since it's possible that the following will free a task
  73.     structure that is used for some time afterwards it's
  74.     necessary to protect the free memory list so that nobody
  75.     can allocate that memory.
  76.     */
  77.     Forbid();
  78.  
  79.     /* Free all memory in the tc_MemEntry list. */
  80.     while((mb=(struct MemList *)RemHead(&task->tc_MemEntry))!=NULL)
  81.     /* Free one MemList node */
  82.     FreeEntry(mb);
  83.  
  84.     /* Changing the task lists always needs a Disable(). */
  85.     Disable();
  86.  
  87.     /* Freeing myself? */
  88.     if(task==SysBase->ThisTask)
  89.     {
  90.     /* Can't do that - let the dispatcher do it. */
  91.     task->tc_State=TS_REMOVED;
  92.  
  93.     /*
  94.         Since I don't know how many levels of Forbid()
  95.         are already pending I set a default value.
  96.     */
  97.     SysBase->TDNestCnt=-1;
  98.  
  99.     /* And force a task switch */
  100.     Switch();
  101.     /* Does not return. */
  102.     }
  103.     else
  104.     /* Good luck. Freeing other tasks is simple. */
  105.     Remove(&task->tc_Node);
  106.  
  107.     /* All done. */
  108.     Enable();
  109.     Permit();
  110.  
  111.     ReturnVoid ("RemTask");
  112.     AROS_LIBFUNC_EXIT
  113. }
  114.  
  115.  
  116.