2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
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 /*****************************************************************************
25 AROS_LH1(void, RemTask
,
28 AROS_LHA(struct Task
*, task
, A1
),
31 struct ExecBase
*, SysBase
, 48, Exec
)
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.
41 task - Task to be removed. NULL means current task.
58 ******************************************************************************/
64 /* A value of NULL means current task */
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
74 suicide
= (task
== SysBase
->ThisTask
);
76 DREMTASK("Removing itself");
78 /* Remove() here, before freeing the MemEntry list. Because
79 the MemEntry list might contain the task struct itself! */
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
;
94 KrnDeleteContext(et
->et_RegFrame
);
96 /* Uninitialize ETask structure */
97 DREMTASK("Cleaning up ETask et=%p", et
);
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? */
112 /* Changing the task lists always needs a 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
126 /* Does not return. */