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_NewTasks
);
41 NEWLIST(&TaskResBase
->trb_LockedLists
);
43 SysBase
->lb_TaskResBase
= (struct Library
*)TaskResBase
;
45 TaskResBase
->trb_RemTask
= SetFunction((struct Library
*)SysBase
, -48*LIB_VECTSIZE
, AROS_SLIB_ENTRY(RemTask
, Task
, 48));
46 TaskResBase
->trb_NewAddTask
= SetFunction((struct Library
*)SysBase
, -176*LIB_VECTSIZE
, AROS_SLIB_ENTRY(NewAddTask
, Task
, 176));
48 InitSemaphore(&TaskResBase
->trb_Sem
);
51 Add existing tasks to our internal list ..
53 #if defined(__AROSEXEC_SMP__)
54 listLock
= KrnSpinLock(&PrivExecBase(SysBase
)->TaskRunningSpinLock
, NULL
, SPINLOCK_MODE_READ
);
56 ForeachNode(&PrivExecBase(SysBase
)->TaskRunning
, curTask
)
58 if ((taskEntry
= AllocMem(sizeof(struct TaskListEntry
), MEMF_CLEAR
)) != NULL
)
60 D(bug("[TaskRes] 0x%p [R ] %02d %s\n", curTask
, GetIntETask(curTask
)->iet_CpuNumber
, curTask
->tc_Node
.ln_Name
));
61 taskEntry
->tle_Task
= curTask
;
62 AddTail(&TaskResBase
->trb_TaskList
, &taskEntry
->tle_Node
);
65 KrnSpinUnLock(listLock
);
67 listLock
= KrnSpinLock(&PrivExecBase(SysBase
)->TaskSpinningLock
, NULL
, SPINLOCK_MODE_READ
);
69 ForeachNode(&PrivExecBase(SysBase
)->TaskSpinning
, curTask
)
71 if ((taskEntry
= AllocMem(sizeof(struct TaskListEntry
), MEMF_CLEAR
)) != NULL
)
73 D(bug("[TaskRes] 0x%p [ S] %02d %s\n", curTask
, GetIntETask(curTask
)->iet_CpuNumber
, curTask
->tc_Node
.ln_Name
));
74 taskEntry
->tle_Task
= curTask
;
75 AddTail(&TaskResBase
->trb_TaskList
, &taskEntry
->tle_Node
);
78 KrnSpinUnLock(listLock
);
80 listLock
= KrnSpinLock(&PrivExecBase(SysBase
)->TaskReadySpinLock
, NULL
, SPINLOCK_MODE_READ
);
82 // TODO : list TaskSpinning tasks..
85 if (SysBase
->ThisTask
)
87 if ((taskEntry
= AllocMem(sizeof(struct TaskListEntry
), MEMF_CLEAR
)) != NULL
)
89 D(bug("[TaskRes] 0x%p [R--] 00 %s\n", SysBase
->ThisTask
, SysBase
->ThisTask
->tc_Node
.ln_Name
));
90 taskEntry
->tle_Task
= SysBase
->ThisTask
;
91 AddTail(&TaskResBase
->trb_TaskList
, &taskEntry
->tle_Node
);
95 ForeachNode(&SysBase
->TaskReady
, curTask
)
97 if ((taskEntry
= AllocMem(sizeof(struct TaskListEntry
), MEMF_CLEAR
)) != NULL
)
99 D(bug("[TaskRes] 0x%p [-R-] -- %s\n", curTask
, curTask
->tc_Node
.ln_Name
));
100 taskEntry
->tle_Task
= curTask
;
101 AddTail(&TaskResBase
->trb_TaskList
, &taskEntry
->tle_Node
);
104 #if defined(__AROSEXEC_SMP__)
105 KrnSpinUnLock(listLock
);
107 listLock
= KrnSpinLock(&PrivExecBase(SysBase
)->TaskWaitSpinLock
, NULL
, SPINLOCK_MODE_READ
);
110 ForeachNode(&SysBase
->TaskWait
, curTask
)
112 if ((taskEntry
= AllocMem(sizeof(struct TaskListEntry
), MEMF_CLEAR
)) != NULL
)
114 D(bug("[TaskRes] 0x%p [--W] -- %s\n", curTask
, curTask
->tc_Node
.ln_Name
));
115 taskEntry
->tle_Task
= curTask
;
116 AddTail(&TaskResBase
->trb_TaskList
, &taskEntry
->tle_Node
);
120 #if defined(__AROSEXEC_SMP__)
121 KrnSpinUnLock(listLock
);
130 static LONG
taskres_Exit(struct TaskResBase
*TaskResBase
)
132 SetFunction((struct Library
*)SysBase
, -176*LIB_VECTSIZE
, TaskResBase
->trb_NewAddTask
);
133 SetFunction((struct Library
*)SysBase
, -48*LIB_VECTSIZE
, TaskResBase
->trb_RemTask
);
135 CloseLibrary(TaskResBase
->trb_UtilityBase
);
140 ADD2INITLIB(taskres_Init
, 0)
142 ADD2EXPUNGELIB(taskres_Exit
, 0)