2 Copyright © 1995-2017, The AROS Development Team. All rights reserved.
5 Desc: exec.library's internal service task. Performs memory management according
6 to task scheduler's requests.
10 #include <exec/execbase.h>
11 #include <exec/tasks.h>
12 #include <aros/libcall.h>
13 #include <proto/exec.h>
15 #include "exec_intern.h"
16 #include "exec_util.h"
17 #include "exec_debug.h"
19 void ServiceTask(struct ExecBase
*SysBase
)
22 struct MemList
*mb
, *mbnext
;
24 DINIT("ServiceTask: Started up");
30 while ((task
= (struct Task
*)GetMsg(PrivExecBase(SysBase
)->ServicePort
)))
32 DREMTASK("ServiceTask: Request for task 0x%p, state %08X\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
)
44 DREMTASK("ServiceTask: Removal request for task 0x%p <%s>", task
, task
->tc_Node
.ln_Name
);
46 // TODO: Make sure the task has terminated..
47 task
->tc_State
= TS_INVALID
;
50 * Note tc_MemEntry list is part of the task structure which
51 * usually is also placed in tc_MemEntry. MungWall_Check()
52 * will fill freed memory and destroy our list while we are
53 * iterating or the freed memory including our list could be
54 * reused by some other task. We take special care of this by
55 * resetting ln_Succ of the last node to NULL. This way we
56 * avoid getting back to our List structure.
58 task
->tc_MemEntry
.lh_TailPred
->ln_Succ
= NULL
;
60 for (mb
= (struct MemList
*)task
->tc_MemEntry
.lh_Head
; mb
; mb
= mbnext
)
62 /* Free one MemList node */
63 mbnext
= (struct MemList
*)mb
->ml_Node
.ln_Succ
;
65 DREMTASK("ServiceTask: Freeing MemList 0x%p", mb
);
71 /* FIXME: Add fault handling here. Perhaps kernel-level GURU. */
72 DREMTASK("ServiceTask: task 0x%p <%s> not in tombstoned state!\n", task
, task
->tc_Node
.ln_Name
);
73 DREMTASK("ServiceTask: state = %08X\n", task
->tc_State
);
74 /* The task is ready to run again. Move it back to TaskReady list. */
75 #if !defined(EXEC_REMTASK_NEEDSSWITCH)
76 task
->tc_State
= TS_READY
;
77 Enqueue(&SysBase
->TaskReady
, &task
->tc_Node
);
79 krnSysCallReschedTask(task
, TS_READY
);
85 WaitPort(PrivExecBase(SysBase
)->ServicePort
);