2 Copyright © 2015-2017, The AROS Development Team. All rights reserved.
8 #include <aros/debug.h>
9 #include <aros/symbolsets.h>
11 #include <proto/exec.h>
13 #include "task_intern.h"
15 void TaskResAddTask(struct TaskResBase
*TaskResBase
, struct Task
*task
)
17 struct TaskListEntry
*newEntry
;
19 if ((newEntry
= AllocMem(sizeof(struct TaskListEntry
), MEMF_CLEAR
)) != NULL
)
21 D(bug("[TaskRes] TaskResAddTask: taskentry @ 0x%p for '%s'\n", newEntry
, task
->tc_Node
.ln_Name
));
22 newEntry
->tle_Task
= task
;
23 if (IsListEmpty(&TaskResBase
->trb_LockedLists
))
24 AddTail(&TaskResBase
->trb_TaskList
, &newEntry
->tle_Node
);
26 AddTail(&TaskResBase
->trb_NewTasks
, &newEntry
->tle_Node
);
30 AROS_LH4(APTR
, NewAddTask
,
31 AROS_LHA(struct Task
*, task
, A1
),
32 AROS_LHA(APTR
, initialPC
, A2
),
33 AROS_LHA(APTR
, finalPC
, A3
),
34 AROS_LHA(struct TagItem
*, tagList
, A4
),
35 struct ExecBase
*, SysBase
, 176, Task
)
40 struct TaskResBase
*TaskResBase
;
42 TaskResBase
= (struct TaskResBase
*)SysBase
->lb_TaskResBase
;
44 D(bug("[TaskRes] NewAddTask(0x%p)\n", task
));
46 newTask
= AROS_CALL4(APTR
, TaskResBase
->trb_NewAddTask
,
47 AROS_LCA(struct Task
*, task
, A1
),
48 AROS_LCA(APTR
, initialPC
, A2
),
49 AROS_LCA(APTR
, finalPC
, A3
),
50 AROS_LCA(struct TagItem
*, tagList
, A4
),
51 struct ExecBase
*, SysBase
);
53 D(bug("[TaskRes] NewAddTask: task @ 0x%p\n", newTask
));
56 TaskResAddTask(TaskResBase
, newTask
);
63 AROS_LH1(void, RemTask
,
64 AROS_LHA(struct Task
*, task
, A1
),
65 struct ExecBase
*, SysBase
, 48, Task
)
69 struct Task
*findTask
= task
;
70 struct TaskListEntry
*taskEntry
, *tmpEntry
;
71 struct TaskResBase
*TaskResBase
;
74 TaskResBase
= (struct TaskResBase
*)SysBase
->lb_TaskResBase
;
77 findTask
= FindTask(NULL
);
80 bug("[TaskRes] RemTask(0x%p)\n", task
);
82 bug("[TaskRes] Real task @ 0x%p\n", findTask
);
85 ForeachNodeSafe(&TaskResBase
->trb_NewTasks
, taskEntry
, tmpEntry
)
87 if (taskEntry
->tle_Task
== findTask
)
89 D(bug("[TaskRes] RemTask: destroying new entry @ 0x%p\n", taskEntry
));
90 Remove(&taskEntry
->tle_Node
);
91 FreeMem(taskEntry
, sizeof(struct TaskListEntry
));
99 #if !defined(__AROSEXEC_SMP__)
100 /* Don't let any other task interfere with us at the moment */
103 EXEC_SPINLOCK_LOCK(&TaskResBase
->TaskListSpinLock
, NULL
, SPINLOCK_MODE_WRITE
);
105 ForeachNodeSafe(&TaskResBase
->trb_TaskList
, taskEntry
, tmpEntry
)
107 if (taskEntry
->tle_Task
== findTask
)
109 D(bug("[TaskRes] RemTask: taskentry @ 0x%p for '%s'\n", taskEntry
, task
->tc_Node
.ln_Name
));
110 if (IsListEmpty(&TaskResBase
->trb_LockedLists
))
112 D(bug("[TaskRes] RemTask: destroying entry\n"));
113 Remove(&taskEntry
->tle_Node
);
114 FreeMem(taskEntry
, sizeof(struct TaskListEntry
));
118 D(bug("[TaskRes] RemTask: flag entry for removal\n"));
119 taskEntry
->tle_Task
= NULL
;
124 #if !defined(__AROSEXEC_SMP__)
127 EXEC_SPINLOCK_UNLOCK(&TaskResBase
->TaskListSpinLock
);
131 D(bug("[TaskRes] RemTask: Calling original Exec->RemTask()\n"));
133 if (TaskResBase
->trb_RemTask
)
135 AROS_CALL1(void, TaskResBase
->trb_RemTask
,
136 AROS_LCA(struct Task
*, task
, A1
),
137 struct ExecBase
*, SysBase
);