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>
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
);
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
)
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
));
57 TaskResAddTask(TaskResBase
, newTask
);
64 AROS_LH1(void, RemTask
,
65 AROS_LHA(struct Task
*, task
, A1
),
66 struct ExecBase
*, SysBase
, 48, Task
)
70 struct Task
*findTask
= task
;
71 struct TaskListEntry
*taskEntry
, *tmpEntry
;
72 struct TaskResBase
*TaskResBase
;
75 TaskResBase
= (struct TaskResBase
*)SysBase
->lb_TaskResBase
;
78 findTask
= FindTask(NULL
);
81 bug("[TaskRes] RemTask(0x%p)\n", 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
));
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
));
113 D(bug("[TaskRes] RemTask: flag entry for removal\n"));
114 taskEntry
->tle_Task
= NULL
;
121 if (TaskResBase
->trb_RemTask
)
123 AROS_CALL1(APTR
, TaskResBase
->trb_RemTask
,
124 AROS_LCA(struct Task
*, task
, A1
),
125 struct ExecBase
*, SysBase
);