Updated PCI IDs to latest snapshot.
[tangerine.git] / arch / i386-pc / exec / remtask.c
blob3eb7507004ffaa7c74ef67247cd4a94a8c9058ed
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>
13 #include "exec_util.h"
14 #include "exec_debug.h"
15 #ifndef DEBUG_RemTask
16 # define DEBUG_RemTask 0
17 #endif
18 #undef DEBUG
19 #if DEBUG_RemTask
20 # define DEBUG 1
21 #endif
22 #include <aros/debug.h>
24 extern void Exec_Dispatch();
26 /*****************************************************************************
28 NAME */
30 AROS_LH1(void, RemTask,
32 /* SYNOPSIS */
33 AROS_LHA(struct Task *, task, A1),
35 /* LOCATION */
36 struct ExecBase *, SysBase, 48, Exec)
38 /* FUNCTION
39 Remove a task from the task lists. All memory in the tc_MemEntry list
40 is freed and a rescedule is done. It's safe to call RemTask() out
41 of Forbid() or Disable().
42 This function is one way to get rid of the current task. The other way
43 is to fall through the end of the entry point.
45 INPUTS
46 task - Task to be removed. NULL means current task.
48 RESULT
50 NOTES
52 EXAMPLE
54 BUGS
56 SEE ALSO
57 AddTask()
59 INTERNALS
61 HISTORY
63 ******************************************************************************/
65 AROS_LIBFUNC_INIT
66 struct MemList *mb;
67 struct ETask *et;
69 /* A value of NULL means current task */
70 if (task==NULL)
71 task=SysBase->ThisTask;
73 D(bug("Call RemTask (%08lx (\"%s\"))\n", task, task->tc_Node.ln_Name));
76 Since it's possible that the following will free a task
77 structure that is used for some time afterwards it's
78 necessary to protect the free memory list so that nobody
79 can allocate that memory.
81 Forbid();
83 /* Remove() here, before freeing the MemEntry list. Because
84 the MemEntry list might contain the task struct itself! */
86 if(task != SysBase->ThisTask)
88 Remove(&task->tc_Node);
91 /* Free all memory in the tc_MemEntry list. */
92 while((mb=(struct MemList *)RemHead(&task->tc_MemEntry))!=NULL)
93 /* Free one MemList node */
94 FreeEntry(mb);
96 /* Uninitialize ETask structure */
97 et = GetETask(task);
98 if(et != NULL)
100 CleanupETask(task, et);
103 /* Changing the task lists always needs a Disable(). */
104 Disable();
106 /* Freeing myself? */
107 if(task==SysBase->ThisTask)
109 /* Can't do that - let the dispatcher do it. */
110 task->tc_State=TS_REMOVED;
113 Since I don't know how many levels of Forbid()
114 are already pending I set a default value.
116 SysBase->TDNestCnt=-1;
118 // task->tc_Node.ln_Pred->ln_Succ = task->tc_Node.ln_Succ;
119 // task->tc_Node.ln_Succ->ln_Pred = task->tc_Node.ln_Pred;
121 /* And force a task switch. Note: Dispatch, not Switch,
122 because the state of thistask must not be saved ->
123 after all the mem for the task + intetask + context
124 could already have been freed by the FreeEntry() call
125 above!!! */
128 Supervisor(__AROS_GETVECADDR(SysBase, 10));
129 /* Does not return. */
132 /* All done. */
133 Enable();
134 Permit();
136 ReturnVoid ("RemTask");
137 AROS_LIBFUNC_EXIT