Updated PCI IDs to latest snapshot.
[tangerine.git] / arch / ppc-chrp / exec / remtask.c
blob6b293644b70565a88fea31991e0fe83f2c7b09d0
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Remove a task
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 #include <proto/kernel.h>
14 extern void *priv_KernelBase;
16 #include "etask.h"
17 #include "exec_util.h"
19 #include "exec_debug.h"
20 #ifndef DEBUG_RemTask
21 # define DEBUG_RemTask 0
22 #endif
23 #undef DEBUG
24 #if DEBUG_RemTask
25 # define DEBUG 1
26 #endif
27 #include <aros/debug.h>
29 /*****************************************************************************
31 NAME */
33 AROS_LH1(void, RemTask,
35 /* SYNOPSIS */
36 AROS_LHA(struct Task *, task, A1),
38 /* LOCATION */
39 struct ExecBase *, SysBase, 48, Exec)
41 /* FUNCTION
42 Remove a task from the task lists. All memory in the tc_MemEntry list
43 is freed and a rescedule is done. It's safe to call RemTask() out
44 of Forbid() or Disable().
45 This function is one way to get rid of the current task. The other way
46 is to fall through the end of the entry point.
48 INPUTS
49 task - Task to be removed. NULL means current task.
51 RESULT
53 NOTES
55 EXAMPLE
57 BUGS
59 SEE ALSO
60 AddTask()
62 INTERNALS
64 HISTORY
66 ******************************************************************************/
68 AROS_LIBFUNC_INIT
69 struct MemList *mb;
70 void *KernelBase = priv_KernelBase;
71 struct ETask *et;
73 /* A value of NULL means current task */
74 if (task==NULL)
75 task=SysBase->ThisTask;
77 D(bug("[exec] Call RemTask (%012lx (\"%s\"))\n", task, task->tc_Node.ln_Name));
80 Since it's possible that the following will free a task
81 structure that is used for some time afterwards it's
82 necessary to protect the free memory list so that nobody
83 can allocate that memory.
85 Forbid();
87 /* Remove() here, before freeing the MemEntry list. Because
88 the MemEntry list might contain the task struct itself! */
90 if(task != SysBase->ThisTask)
92 Remove(&task->tc_Node);
95 KrnDeleteContext(GetIntETask(task)->iet_Context);
97 et = GetETask(task);
98 if (et != NULL)
100 CleanupETask(task, et);
103 /* Free all memory in the tc_MemEntry list. */
104 while((mb=(struct MemList *)RemHead(&task->tc_MemEntry))!=NULL)
105 /* Free one MemList node */
106 FreeEntry(mb);
108 /* Changing the task lists always needs a Disable(). */
109 Disable();
111 /* Freeing myself? */
112 if(task==SysBase->ThisTask)
114 /* Can't do that - let the dispatcher do it. */
115 task->tc_State=TS_REMOVED;
118 Since I don't know how many levels of Forbid()
119 are already pending I set a default value.
121 SysBase->TDNestCnt=-1;
123 // task->tc_Node.ln_Pred->ln_Succ = task->tc_Node.ln_Succ;
124 // task->tc_Node.ln_Succ->ln_Pred = task->tc_Node.ln_Pred;
126 /* And force a task switch. Note: Dispatch, not Switch,
127 because the state of thistask must not be saved ->
128 after all the mem for the task + intetask + context
129 could already have been freed by the FreeEntry() call
130 above!!! */
132 KrnDispatch();
133 /* Does not return. */
136 /* All done. */
137 Enable();
138 Permit();
140 ReturnVoid ("RemTask");
141 AROS_LIBFUNC_EXIT