added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / arch / i386-pc / exec / remtask.c
blob22261f247965e18e5e83fed7d5cdb1cd04fe3a2e
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_debug.h"
14 #ifndef DEBUG_RemTask
15 # define DEBUG_RemTask 0
16 #endif
17 #undef DEBUG
18 #if DEBUG_RemTask
19 # define DEBUG 1
20 #endif
21 #include <aros/debug.h>
23 extern void Exec_Dispatch();
25 /*****************************************************************************
27 NAME */
29 AROS_LH1(void, RemTask,
31 /* SYNOPSIS */
32 AROS_LHA(struct Task *, task, A1),
34 /* LOCATION */
35 struct ExecBase *, SysBase, 48, Exec)
37 /* FUNCTION
38 Remove a task from the task lists. All memory in the tc_MemEntry list
39 is freed and a rescedule is done. It's safe to call RemTask() out
40 of Forbid() or Disable().
41 This function is one way to get rid of the current task. The other way
42 is to fall through the end of the entry point.
44 INPUTS
45 task - Task to be removed. NULL means current task.
47 RESULT
49 NOTES
51 EXAMPLE
53 BUGS
55 SEE ALSO
56 AddTask()
58 INTERNALS
60 HISTORY
62 ******************************************************************************/
64 AROS_LIBFUNC_INIT
65 struct MemList *mb;
67 /* A value of NULL means current task */
68 if (task==NULL)
69 task=SysBase->ThisTask;
71 D(bug("Call RemTask (%08lx (\"%s\"))\n", task, task->tc_Node.ln_Name));
74 Since it's possible that the following will free a task
75 structure that is used for some time afterwards it's
76 necessary to protect the free memory list so that nobody
77 can allocate that memory.
79 Forbid();
81 /* Remove() here, before freeing the MemEntry list. Because
82 the MemEntry list might contain the task struct itself! */
84 if(task != SysBase->ThisTask)
86 Remove(&task->tc_Node);
89 /* Free all memory in the tc_MemEntry list. */
90 while((mb=(struct MemList *)RemHead(&task->tc_MemEntry))!=NULL)
91 /* Free one MemList node */
92 FreeEntry(mb);
94 /* Changing the task lists always needs a Disable(). */
95 Disable();
97 /* Freeing myself? */
98 if(task==SysBase->ThisTask)
100 /* Can't do that - let the dispatcher do it. */
101 task->tc_State=TS_REMOVED;
104 Since I don't know how many levels of Forbid()
105 are already pending I set a default value.
107 SysBase->TDNestCnt=-1;
109 // task->tc_Node.ln_Pred->ln_Succ = task->tc_Node.ln_Succ;
110 // task->tc_Node.ln_Succ->ln_Pred = task->tc_Node.ln_Pred;
112 /* And force a task switch. Note: Dispatch, not Switch,
113 because the state of thistask must not be saved ->
114 after all the mem for the task + intetask + context
115 could already have been freed by the FreeEntry() call
116 above!!! */
119 Supervisor(__AROS_GETVECADDR(SysBase, 10));
120 /* Does not return. */
123 /* All done. */
124 Enable();
125 Permit();
127 ReturnVoid ("RemTask");
128 AROS_LIBFUNC_EXIT