home *** CD-ROM | disk | FTP | other *** search
/ MACD 4 / MACD4.iso / Emulatory / AROS / exec / remtask.c < prev    next >
Encoding:
C/C++ Source or Header  |  1978-03-06  |  2.8 KB  |  129 lines

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