rom/exec: Added some debug output.
[AROS.git] / rom / exec / remtask.c
blobe57f31d0facc53425d3200fa89ae634afc9b8b20
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Remove a task
6 Lang: english
7 */
9 #include <aros/debug.h>
10 #include <exec/execbase.h>
11 #include <exec/tasks.h>
12 #include <aros/libcall.h>
13 #include <proto/exec.h>
14 #include <proto/kernel.h>
15 #include <aros/symbolsets.h>
17 #include "exec_intern.h"
18 #include "exec_util.h"
19 #include "exec_debug.h"
21 /*****************************************************************************
23 NAME */
25 AROS_LH1(void, RemTask,
27 /* SYNOPSIS */
28 AROS_LHA(struct Task *, task, A1),
30 /* LOCATION */
31 struct ExecBase *, SysBase, 48, Exec)
33 /* FUNCTION
34 Remove a task from the task lists. All memory in the tc_MemEntry list
35 is freed and a rescedule is done. It's safe to call RemTask() out
36 of Forbid() or Disable().
37 This function is one way to get rid of the current task. The other way
38 is to fall through the end of the entry point.
40 INPUTS
41 task - Task to be removed. NULL means current task.
43 RESULT
45 NOTES
47 EXAMPLE
49 BUGS
51 SEE ALSO
52 AddTask()
54 INTERNALS
56 HISTORY
58 ******************************************************************************/
60 AROS_LIBFUNC_INIT
61 struct ETask *et;
62 BOOL suicide;
64 /* A value of NULL means current task */
65 if (task==NULL)
66 task=SysBase->ThisTask;
68 DREMTASK("RemTask (0x%p (\"%s\"))", task, task->tc_Node.ln_Name);
70 /* Don't let any other task interfere with us at the moment
72 Forbid();
74 suicide = (task == SysBase->ThisTask);
75 if (suicide)
76 DREMTASK("Removing itself");
78 /* Remove() here, before freeing the MemEntry list. Because
79 the MemEntry list might contain the task struct itself! */
81 if (!suicide)
82 Remove(&task->tc_Node);
85 * The task is being removed.
86 * This is an important signal for Alert() which will not attempt to use
87 * the context which is being deleted, for example.
89 task->tc_State = TS_REMOVED;
91 /* Delete context */
92 et = GetETask(task);
93 if (et != NULL)
94 KrnDeleteContext(et->et_RegFrame);
96 /* Uninitialize ETask structure */
97 DREMTASK("Cleaning up ETask et=%p", et);
98 CleanupETask(task);
101 * Send task to task cleaner to clean up memory.
102 * This avoids ripping memory from underneath a running Task.
103 * Message is basically a Node, so we use our task's tc_Node as a message.
104 * We use InternalPutMsg() because it won't change ln_Type. Just in case...
106 DREMTASK("Sending to garbage man");
107 InternalPutMsg(((struct IntExecBase *)SysBase)->ServicePort, (struct Message *)task, SysBase);
109 /* Freeing myself? */
110 if (suicide)
112 /* Changing the task lists always needs a Disable(). */
113 Disable();
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 /* And force a task switch. Note: Dispatch, not Switch,
122 because the state of ThisTask must not be saved
125 KrnDispatch();
126 /* Does not return. */
129 /* All done. */
130 Permit();
132 DREMTASK("Success");
134 AROS_LIBFUNC_EXIT