some fixes to accented characters
[tangerine.git] / rom / exec / remtask.c
blob867f1fa1c92e86c8be75c3a7aa0e1735b5d9413d
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 /*****************************************************************************
26 NAME */
28 AROS_LH1(void, RemTask,
30 /* SYNOPSIS */
31 AROS_LHA(struct Task *, task, A1),
33 /* LOCATION */
34 struct ExecBase *, SysBase, 48, Exec)
36 /* FUNCTION
37 Remove a task from the task lists. All memory in the tc_MemEntry list
38 is freed and a rescedule is done. It's safe to call RemTask() out
39 of Forbid() or Disable().
40 This function is one way to get rid of the current task. The other way
41 is to fall through the end of the entry point.
43 INPUTS
44 task - Task to be removed. NULL means current task.
46 RESULT
48 NOTES
50 EXAMPLE
52 BUGS
54 SEE ALSO
55 AddTask()
57 INTERNALS
59 ******************************************************************************/
61 AROS_LIBFUNC_INIT
62 struct MemList *mb;
63 struct ETask *et;
65 /* A value of NULL means current task */
66 if (task==NULL)
67 task=SysBase->ThisTask;
69 D(bug("Call RemTask (%08lx (\"%s\"))\n", task, task->tc_Node.ln_Name));
72 Since it's possible that the following will free a task
73 structure that is used for some time afterwards it's
74 necessary to protect the free memory list so that nobody
75 can allocate that memory.
77 Forbid();
79 /* Remove() here, before freeing the MemEntry list. Because
80 the MemEntry list might contain the task struct itself! */
82 if(task != SysBase->ThisTask)
84 /* disable interrupts when changing the task lists */
85 Disable();
86 Remove(&task->tc_Node);
87 Enable();
89 /* force the task into the removed state, otherwise a received signal
90 * can bring it back to life */
91 task->tc_State = TS_REMOVED;
94 /* Free all memory in the tc_MemEntry list. */
95 while((mb=(struct MemList *)RemHead(&task->tc_MemEntry))!=NULL)
96 /* Free one MemList node */
97 FreeEntry(mb);
99 /* Uninitialize ETask structure */
100 et = GetETask(task);
101 if(et != NULL)
103 CleanupETask(task, et);
106 /* Changing the task lists always needs a Disable(). */
107 Disable();
109 /* Freeing myself? */
110 if(task==SysBase->ThisTask)
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 /* And force a task switch */
122 Switch();
123 /* Does not return. */
126 /* All done. */
127 Enable();
128 Permit();
130 ReturnVoid ("RemTask");
131 AROS_LIBFUNC_EXIT
132 } /* RemTask() */