grub2: bring back build of aros-side grub2 tools
[AROS.git] / rom / task / execfuncs.c
blob0e5149ec11a43247b46f83c82beb9ec072c3ac1e
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>
14 #include "taskres_intern.h"
16 void TaskResAddTask(struct TaskResBase *TaskResBase, struct Task *task)
18 struct TaskListEntry *newEntry;
20 if ((newEntry = AllocMem(sizeof(struct TaskListEntry), MEMF_CLEAR)) != NULL)
22 D(bug("[TaskRes] TaskResAddTask: taskentry @ 0x%p for '%s'\n", newEntry, task->tc_Node.ln_Name));
23 newEntry->tle_Task = task;
24 if (IsListEmpty(&TaskResBase->trb_LockedLists))
25 AddTail(&TaskResBase->trb_TaskList, &newEntry->tle_Node);
26 else
27 AddTail(&TaskResBase->trb_NewTasks, &newEntry->tle_Node);
31 AROS_LH4(APTR, NewAddTask,
32 AROS_LHA(struct Task *, task, A1),
33 AROS_LHA(APTR, initialPC, A2),
34 AROS_LHA(APTR, finalPC, A3),
35 AROS_LHA(struct TagItem *, tagList, A4),
36 struct ExecBase *, SysBase, 176, Task)
38 AROS_LIBFUNC_INIT
40 APTR newTask;
41 struct TaskResBase *TaskResBase;
43 TaskResBase = (struct TaskResBase *)SysBase->lb_TaskResBase;
45 D(bug("[TaskRes] NewAddTask(0x%p)\n", task));
47 newTask = AROS_CALL4(APTR, TaskResBase->trb_NewAddTask,
48 AROS_LCA(struct Task *, task, A1),
49 AROS_LCA(APTR, initialPC, A2),
50 AROS_LCA(APTR, finalPC, A3),
51 AROS_LCA(struct TagItem *, tagList, A4),
52 struct ExecBase *, SysBase);
54 D(bug("[TaskRes] NewAddTask: task @ 0x%p\n", newTask));
56 if (newTask)
57 TaskResAddTask(TaskResBase, newTask);
59 return newTask;
61 AROS_LIBFUNC_EXIT
64 AROS_LH1(void, RemTask,
65 AROS_LHA(struct Task *, task, A1),
66 struct ExecBase *, SysBase, 48, Task)
68 AROS_LIBFUNC_INIT
70 struct Task *findTask = task;
71 struct TaskListEntry *taskEntry, *tmpEntry;
72 struct TaskResBase *TaskResBase;
73 BOOL removed = FALSE;
75 TaskResBase = (struct TaskResBase *)SysBase->lb_TaskResBase;
77 if (!findTask)
78 findTask = FindTask(NULL);
81 bug("[TaskRes] RemTask(0x%p)\n", task);
82 if (findTask != task)
83 bug("[TaskRes] Real task @ 0x%p\n", findTask);
86 ForeachNodeSafe(&TaskResBase->trb_NewTasks, taskEntry, tmpEntry)
88 if (taskEntry->tle_Task == findTask)
90 D(bug("[TaskRes] RemTask: destroying new entry @ 0x%p\n", taskEntry));
91 Remove(&taskEntry->tle_Node);
92 FreeMem(taskEntry, sizeof(struct TaskListEntry));
93 removed = TRUE;
94 break;
98 if (!removed)
100 ForeachNodeSafe(&TaskResBase->trb_TaskList, taskEntry, tmpEntry)
102 if (taskEntry->tle_Task == findTask)
104 D(bug("[TaskRes] RemTask: taskentry @ 0x%p for '%s'\n", taskEntry, task->tc_Node.ln_Name));
105 if (IsListEmpty(&TaskResBase->trb_LockedLists))
107 D(bug("[TaskRes] RemTask: destroying entry\n"));
108 Remove(&taskEntry->tle_Node);
109 FreeMem(taskEntry, sizeof(struct TaskListEntry));
111 else
113 D(bug("[TaskRes] RemTask: flag entry for removal\n"));
114 taskEntry->tle_Task = NULL;
116 break;
121 if (TaskResBase->trb_RemTask)
123 AROS_CALL1(APTR, TaskResBase->trb_RemTask,
124 AROS_LCA(struct Task *, task, A1),
125 struct ExecBase *, SysBase);
127 return;
129 AROS_LIBFUNC_EXIT