2 Copyright © 2015-2017, The AROS Development Team. All rights reserved.
8 #include <aros/debug.h>
9 #include <aros/symbolsets.h>
11 #include <proto/exec.h>
12 #include <proto/execlock.h>
13 #include <resources/execlock.h>
14 #include <resources/task.h>
18 #include "task_intern.h"
20 extern APTR
AROS_SLIB_ENTRY(NewAddTask
, Task
, 176)();
21 extern void AROS_SLIB_ENTRY(RemTask
, Task
, 48)();
23 static LONG
taskres_Init(struct TaskResBase
*TaskResBase
)
26 struct TaskListEntry
*taskEntry
= NULL
;
27 struct Task
*curTask
= NULL
;
29 #if defined(__AROSEXEC_SMP__)
30 void *ExecLockBase
= NULL
;
32 #endif /* TASKRES_ENABLE */
34 KernelBase
= OpenResource("kernel.resource");
38 #if defined(__AROSEXEC_SMP__)
39 TaskResBase
->trb_ExecLock
= OpenResource("execlock.resource");
40 ExecLockBase
= TaskResBase
->trb_ExecLock
;
43 TaskResBase
->trb_UtilityBase
= OpenLibrary("utility.library", 0);
44 if (!TaskResBase
->trb_UtilityBase
)
47 NEWLIST(&TaskResBase
->trb_TaskList
);
48 NEWLIST(&TaskResBase
->trb_NewTasks
);
49 NEWLIST(&TaskResBase
->trb_LockedLists
);
51 SysBase
->lb_TaskResBase
= (struct Library
*)TaskResBase
;
53 InitSemaphore(&TaskResBase
->trb_Sem
);
56 TaskResBase
->trb_RemTask
= SetFunction((struct Library
*)SysBase
, -48*LIB_VECTSIZE
, AROS_SLIB_ENTRY(RemTask
, Task
, 48));
57 TaskResBase
->trb_NewAddTask
= SetFunction((struct Library
*)SysBase
, -176*LIB_VECTSIZE
, AROS_SLIB_ENTRY(NewAddTask
, Task
, 176));
60 Add existing tasks to our internal list ..
62 #if defined(__AROSEXEC_SMP__)
63 ObtainSystemLock(&PrivExecBase(SysBase
)->TaskRunning
, SPINLOCK_MODE_READ
, LOCKF_DISABLE
);
64 ForeachNode(&PrivExecBase(SysBase
)->TaskRunning
, curTask
)
66 if (curTask
->tc_State
& TS_RUN
)
68 if ((taskEntry
= AllocMem(sizeof(struct TaskListEntry
), MEMF_CLEAR
)) != NULL
)
70 D(bug("[TaskRes] 0x%p [R ] %02d %s\n", curTask
, GetIntETask(curTask
)->iet_CpuNumber
, curTask
->tc_Node
.ln_Name
));
71 taskEntry
->tle_Task
= curTask
;
72 AddTail(&TaskResBase
->trb_TaskList
, &taskEntry
->tle_Node
);
76 bug("[TaskRes] Failed to allocate storage for task @ 0x%p!!\n", curTask
);
81 bug("[TaskRes] Invalid Task State %08x for task @ 0x%p\n", curTask
->tc_State
, curTask
);
84 ReleaseSystemLock(&PrivExecBase(SysBase
)->TaskRunning
, LOCKF_DISABLE
);
86 ObtainSystemLock(&PrivExecBase(SysBase
)->TaskSpinning
, SPINLOCK_MODE_READ
, LOCKF_DISABLE
);
87 ForeachNode(&PrivExecBase(SysBase
)->TaskSpinning
, curTask
)
89 if (curTask
->tc_State
& TS_SPIN
)
91 if ((taskEntry
= AllocMem(sizeof(struct TaskListEntry
), MEMF_CLEAR
)) != NULL
)
93 D(bug("[TaskRes] 0x%p [ S] %02d %s\n", curTask
, GetIntETask(curTask
)->iet_CpuNumber
, curTask
->tc_Node
.ln_Name
));
94 taskEntry
->tle_Task
= curTask
;
95 AddTail(&TaskResBase
->trb_TaskList
, &taskEntry
->tle_Node
);
99 bug("[TaskRes] Failed to allocate storage for task @ 0x%p!!\n", curTask
);
104 bug("[TaskRes] Invalid Task State %08x for task @ 0x%p\n", curTask
->tc_State
, curTask
);
107 ReleaseSystemLock(&PrivExecBase(SysBase
)->TaskSpinning
, LOCKF_DISABLE
);
109 ObtainSystemLock(&SysBase
->TaskReady
, SPINLOCK_MODE_READ
, LOCKF_DISABLE
);
110 // TODO : list TaskSpinning tasks..
113 if (SysBase
->ThisTask
)
115 if (SysBase
->ThisTask
->tc_State
& TS_RUN
)
117 if ((taskEntry
= AllocMem(sizeof(struct TaskListEntry
), MEMF_CLEAR
)) != NULL
)
119 D(bug("[TaskRes] 0x%p [R--] 00 %s\n", SysBase
->ThisTask
, SysBase
->ThisTask
->tc_Node
.ln_Name
));
120 taskEntry
->tle_Task
= SysBase
->ThisTask
;
121 AddTail(&TaskResBase
->trb_TaskList
, &taskEntry
->tle_Node
);
125 bug("[TaskRes] Failed to allocate storage for task @ 0x%p!!\n", SysBase
->ThisTask
);
130 bug("[TaskRes] Invalid Task State %08x for task @ 0x%p\n", SysBase
->ThisTask
->tc_State
, curTask
);
134 ForeachNode(&SysBase
->TaskReady
, curTask
)
136 if (curTask
->tc_State
& (TS_READY
|TS_RUN
))
138 if ((taskEntry
= AllocMem(sizeof(struct TaskListEntry
), MEMF_CLEAR
)) != NULL
)
140 D(bug("[TaskRes] 0x%p [-R-] -- %s\n", curTask
, curTask
->tc_Node
.ln_Name
));
141 taskEntry
->tle_Task
= curTask
;
142 AddTail(&TaskResBase
->trb_TaskList
, &taskEntry
->tle_Node
);
146 bug("[TaskRes] Failed to allocate storage for task @ 0x%p!!\n", curTask
);
151 bug("[TaskRes] Invalid Task State %08x for task @ 0x%p\n", curTask
->tc_State
, curTask
);
154 #if defined(__AROSEXEC_SMP__)
155 ReleaseSystemLock(&SysBase
->TaskReady
, LOCKF_DISABLE
);
157 ObtainSystemLock(&SysBase
->TaskWait
, SPINLOCK_MODE_READ
, LOCKF_DISABLE
);
159 ForeachNode(&SysBase
->TaskWait
, curTask
)
161 if (curTask
->tc_State
& TS_WAIT
)
163 if ((taskEntry
= AllocMem(sizeof(struct TaskListEntry
), MEMF_CLEAR
)) != NULL
)
165 D(bug("[TaskRes] 0x%p [--W] -- %s\n", curTask
, curTask
->tc_Node
.ln_Name
));
166 taskEntry
->tle_Task
= curTask
;
167 AddTail(&TaskResBase
->trb_TaskList
, &taskEntry
->tle_Node
);
171 bug("[TaskRes] Failed to allocate storage for task @ 0x%p!!\n", curTask
);
176 bug("[TaskRes] Invalid Task State %08x for task @ 0x%p\n", curTask
->tc_State
, curTask
);
179 #if defined(__AROSEXEC_SMP__)
180 ReleaseSystemLock(&SysBase
->TaskWait
, LOCKF_DISABLE
);
185 #endif /* TASKRES_ENABLE */
190 static LONG
taskres_Exit(struct TaskResBase
*TaskResBase
)
192 #ifdef TASKRES_ENABLE
193 SetFunction((struct Library
*)SysBase
, -176*LIB_VECTSIZE
, TaskResBase
->trb_NewAddTask
);
194 SetFunction((struct Library
*)SysBase
, -48*LIB_VECTSIZE
, TaskResBase
->trb_RemTask
);
195 #endif /* TASKRES_ENABLE */
197 CloseLibrary(TaskResBase
->trb_UtilityBase
);
202 ADD2INITLIB(taskres_Init
, 0)
204 ADD2EXPUNGELIB(taskres_Exit
, 0)