only bring in as many sdl things as are strictly necessary
[tangerine.git] / arch / ppc-sam440 / exec / remtask.c
blob8ea619afa13dfcb49a2d2ac81856df7bc34d10b0
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 #include "../kernel/kernel_intern.h"
16 #include "exec_util.h"
17 #include "exec_debug.h"
18 #ifndef DEBUG_RemTask
19 # define DEBUG_RemTask 0
20 #endif
21 #undef DEBUG
22 #if DEBUG_RemTask
23 # define DEBUG 1
24 #endif
25 #include <aros/debug.h>
27 /*****************************************************************************
29 NAME */
31 AROS_LH1(void, RemTask,
33 /* SYNOPSIS */
34 AROS_LHA(struct Task *, task, A1),
36 /* LOCATION */
37 struct ExecBase *, SysBase, 48, Exec)
39 /* FUNCTION
40 Remove a task from the task lists. All memory in the tc_MemEntry list
41 is freed and a rescedule is done. It's safe to call RemTask() out
42 of Forbid() or Disable().
43 This function is one way to get rid of the current task. The other way
44 is to fall through the end of the entry point.
46 INPUTS
47 task - Task to be removed. NULL means current task.
49 RESULT
51 NOTES
53 EXAMPLE
55 BUGS
57 SEE ALSO
58 AddTask()
60 INTERNALS
62 HISTORY
64 ******************************************************************************/
66 AROS_LIBFUNC_INIT
67 struct MemList *mb;
68 struct ETask *et;
70 /* A value of NULL means current task */
71 if (task==NULL)
72 task=SysBase->ThisTask;
74 D(bug("[exec] Call RemTask (%012lx (\"%s\"))\n", task, task->tc_Node.ln_Name));
77 Since it's possible that the following will free a task
78 structure that is used for some time afterwards it's
79 necessary to protect the free memory list so that nobody
80 can allocate that memory.
82 Forbid();
84 /* Remove() here, before freeing the MemEntry list. Because
85 the MemEntry list might contain the task struct itself! */
87 if(task != SysBase->ThisTask)
89 Remove(&task->tc_Node);
92 /* Free all memory in the tc_MemEntry list. */
93 while((mb=(struct MemList *)RemHead(&task->tc_MemEntry))!=NULL)
94 /* Free one MemList node */
95 FreeEntry(mb);
97 /* Uninitialize ETask structure */
98 et = GetETask(task);
99 if(et != NULL)
101 CleanupETask(task, et);
104 /* Changing the task lists always needs a Disable(). */
105 Disable();
107 /* Freeing myself? */
108 if(task==SysBase->ThisTask)
110 void *KernelBase = getKernelBase();
112 /* Can't do that - let the dispatcher do it. */
113 task->tc_State=TS_REMOVED;
116 Since I don't know how many levels of Forbid()
117 are already pending I set a default value.
119 SysBase->TDNestCnt=-1;
121 // task->tc_Node.ln_Pred->ln_Succ = task->tc_Node.ln_Succ;
122 // task->tc_Node.ln_Succ->ln_Pred = task->tc_Node.ln_Pred;
124 /* And force a task switch. Note: Dispatch, not Switch,
125 because the state of thistask must not be saved ->
126 after all the mem for the task + intetask + context
127 could already have been freed by the FreeEntry() call
128 above!!! */
130 KrnDispatch();
131 /* Does not return. */
134 /* All done. */
135 Enable();
136 Permit();
138 ReturnVoid ("RemTask");
139 AROS_LIBFUNC_EXIT