Removed __startup attribute. It is already present in AROS_SHxx definition, and doubl...
[AROS.git] / rom / exec / service.c
blob6512b439ae925d994c485d05b68690f554003eb5
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: exec.library's internal service task. Performs memory management according
6 to task scheduler's requests.
7 Lang: english
8 */
10 #include <aros/debug.h>
11 #include <exec/execbase.h>
12 #include <exec/tasks.h>
13 #include <aros/libcall.h>
14 #include <proto/exec.h>
15 #include <proto/kernel.h>
17 #include "exec_intern.h"
18 #include "exec_util.h"
19 #include "exec_debug.h"
21 void ServiceTask(struct ExecBase *SysBase)
23 DINIT("Service task started up");
26 { /* forever */
27 struct Task *task;
28 struct MemList *mb, *mbnext;
30 while ((task = (struct Task *)GetMsg(PrivExecBase(SysBase)->ServicePort)))
32 D(bug("[exec] Service request for task 0x%p, state %d\n", task, task->tc_State));
35 * If we ever need to use TSS here, we'll need to explicitly check its size here.
36 * However we don't need this, because we never call so high-level libraries.
37 * So, currently we ignore this.
40 switch (task->tc_State)
42 case TS_REMOVED:
43 DREMTASK("Removal request for task 0x%p <%s>", task, task->tc_Node.ln_Name);
46 * Note tc_MemEntry list is part of the task structure which
47 * usually is also placed in tc_MemEntry. MungWall_Check()
48 * will fill freed memory and destroy our list while we are
49 * iterating or the freed memory including our list could be
50 * reused by some other task. We take special care of this by
51 * resetting ln_Succ of the last node to NULL. This way we
52 * avoid getting back to our List structure.
54 task->tc_MemEntry.lh_TailPred->ln_Succ = NULL;
56 for (mb = (struct MemList *)task->tc_MemEntry.lh_Head; mb; mb = mbnext)
58 /* Free one MemList node */
59 mbnext = (struct MemList *)mb->ml_Node.ln_Succ;
61 DREMTASK("Freeing MemList 0x%p", mb);
62 FreeEntry(mb);
64 break;
66 default:
67 /* FIXME: Add fault handling here. Perhaps kernel-level GURU. */
69 /* The task is ready to run again. Move it back to TaskReady list. */
70 task->tc_State = TS_READY;
71 Enqueue(&SysBase->TaskReady,&task->tc_Node);
73 break;
77 WaitPort(PrivExecBase(SysBase)->ServicePort);
78 } while(1);