cleanup debug
[AROS.git] / rom / task / init.c
blobe699d08e3edc6f242717c4c2e004b76c6726d3a6
1 /*
2 Copyright © 2015, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define DEBUG 0
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>
16 #include "etask.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__)
26 spinlock_t *listLock;
27 #endif
28 struct TaskListEntry *taskEntry = NULL;
29 struct Task *curTask = NULL;
31 KernelBase = OpenResource("kernel.resource");
32 if (!KernelBase)
33 return FALSE;
35 TaskResBase->trb_UtilityBase = OpenLibrary("utility.library", 0);
36 if (!TaskResBase->trb_UtilityBase)
37 return FALSE;
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);
52 Forbid();
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);
63 Permit();
64 listLock = KrnSpinLock(&PrivExecBase(SysBase)->TaskReadySpinLock, NULL, SPINLOCK_MODE_READ);
65 Forbid();
66 // TODO : list TaskSpinning tasks..
67 #else
68 Disable();
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);
78 #endif
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);
90 Permit();
91 listLock = KrnSpinLock(&PrivExecBase(SysBase)->TaskWaitSpinLock, NULL, SPINLOCK_MODE_READ);
92 Forbid();
93 #endif
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);
106 Permit();
107 #else
108 Enable();
109 #endif
111 return TRUE;
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);
121 return TRUE;
124 ADD2INITLIB(taskres_Init, 0)
126 ADD2EXPUNGELIB(taskres_Exit, 0)