grub2: bring back build of aros-side grub2 tools
[AROS.git] / rom / task / init.c
blob05ead2d65deda658b0dc62da46a25a3709111f37
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_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);
55 Forbid();
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);
66 Permit();
67 listLock = KrnSpinLock(&PrivExecBase(SysBase)->TaskSpinningLock, NULL, SPINLOCK_MODE_READ);
68 Forbid();
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);
79 Permit();
80 listLock = KrnSpinLock(&PrivExecBase(SysBase)->TaskReadySpinLock, NULL, SPINLOCK_MODE_READ);
81 Forbid();
82 // TODO : list TaskSpinning tasks..
83 #else
84 Disable();
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);
94 #endif
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);
106 Permit();
107 listLock = KrnSpinLock(&PrivExecBase(SysBase)->TaskWaitSpinLock, NULL, SPINLOCK_MODE_READ);
108 Forbid();
109 #endif
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);
122 Permit();
123 #else
124 Enable();
125 #endif
127 return TRUE;
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);
137 return TRUE;
140 ADD2INITLIB(taskres_Init, 0)
142 ADD2EXPUNGELIB(taskres_Exit, 0)