2 Copyright © 2015, 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/kernel.h>
13 #include <resources/task.h>
15 #include <exec_intern.h>
18 #include "taskres_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
)
25 #if defined(__AROSEXEC_SMP__)
28 struct TaskListEntry
*taskEntry
= NULL
;
29 struct Task
*curTask
= NULL
;
31 KernelBase
= OpenResource("kernel.resource");
35 TaskResBase
->trb_UtilityBase
= OpenLibrary("utility.library", 0);
36 if (!TaskResBase
->trb_UtilityBase
)
39 NEWLIST(&TaskResBase
->trb_TaskList
);
40 NEWLIST(&TaskResBase
->trb_LockedLists
);
42 SysBase
->lb_TaskResBase
= (struct Library
*)TaskResBase
;
44 TaskResBase
->trb_NewAddTask
= SetFunction((struct Library
*)SysBase
, -176*LIB_VECTSIZE
, AROS_SLIB_ENTRY(NewAddTask
, Task
, 176));
45 TaskResBase
->trb_RemTask
= SetFunction((struct Library
*)SysBase
, -48*LIB_VECTSIZE
, AROS_SLIB_ENTRY(RemTask
, Task
, 48));
48 Add existing tasks to our internal list ..
50 #if defined(__AROSEXEC_SMP__)
51 listLock
= KrnSpinLock(&PrivExecBase(SysBase
)->TaskRunningSpinLock
, NULL
, SPINLOCK_MODE_READ
);
53 ForeachNode(&PrivExecBase(SysBase
)->TaskRunning
, curTask
)
55 if ((taskEntry
= AllocMem(sizeof(struct TaskListEntry
), MEMF_CLEAR
)) != NULL
)
57 D(bug("[TaskRes] 0x%p [R ] %02d %s\n", curTask
, GetIntETask(curTask
)->iet_CpuNumber
, curTask
->tc_Node
.ln_Name
));
58 taskEntry
->tle_Task
= curTask
;
59 AddTail(&TaskResBase
->trb_TaskList
, &taskEntry
->tle_Node
);
62 KrnSpinUnLock(listLock
);
64 listLock
= KrnSpinLock(&PrivExecBase(SysBase
)->TaskReadySpinLock
, NULL
, SPINLOCK_MODE_READ
);
66 // TODO : list TaskSpinning tasks..
69 if (SysBase
->ThisTask
)
71 if ((taskEntry
= AllocMem(sizeof(struct TaskListEntry
), MEMF_CLEAR
)) != NULL
)
73 D(bug("[TaskRes] 0x%p [R--] 00 %s\n", SysBase
->ThisTask
, SysBase
->ThisTask
->tc_Node
.ln_Name
));
74 taskEntry
->tle_Task
= SysBase
->ThisTask
;
75 AddTail(&TaskResBase
->trb_TaskList
, &taskEntry
->tle_Node
);
79 ForeachNode(&SysBase
->TaskReady
, curTask
)
81 if ((taskEntry
= AllocMem(sizeof(struct TaskListEntry
), MEMF_CLEAR
)) != NULL
)
83 D(bug("[TaskRes] 0x%p [-R-] -- %s\n", curTask
, curTask
->tc_Node
.ln_Name
));
84 taskEntry
->tle_Task
= curTask
;
85 AddTail(&TaskResBase
->trb_TaskList
, &taskEntry
->tle_Node
);
88 #if defined(__AROSEXEC_SMP__)
89 KrnSpinUnLock(listLock
);
91 listLock
= KrnSpinLock(&PrivExecBase(SysBase
)->TaskWaitSpinLock
, NULL
, SPINLOCK_MODE_READ
);
94 ForeachNode(&SysBase
->TaskWait
, curTask
)
96 if ((taskEntry
= AllocMem(sizeof(struct TaskListEntry
), MEMF_CLEAR
)) != NULL
)
98 D(bug("[TaskRes] 0x%p [--W] -- %s\n", curTask
, curTask
->tc_Node
.ln_Name
));
99 taskEntry
->tle_Task
= curTask
;
100 AddTail(&TaskResBase
->trb_TaskList
, &taskEntry
->tle_Node
);
104 #if defined(__AROSEXEC_SMP__)
105 KrnSpinUnLock(listLock
);
114 static LONG
taskres_Exit(struct TaskResBase
*TaskResBase
)
116 SetFunction((struct Library
*)SysBase
, -176*LIB_VECTSIZE
, TaskResBase
->trb_NewAddTask
);
117 SetFunction((struct Library
*)SysBase
, -48*LIB_VECTSIZE
, TaskResBase
->trb_RemTask
);
119 CloseLibrary(TaskResBase
->trb_UtilityBase
);
124 ADD2INITLIB(taskres_Init
, 0)
126 ADD2EXPUNGELIB(taskres_Exit
, 0)