try to make sure compiler/include/mmakefile is always refreshed correctly.
[AROS.git] / rom / task / task_execfuncs.c
blob6457a5a3b57499f222266b10eda7821b0d2c1399
1 /*
2 Copyright © 2015-2017, 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>
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);
25 else
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)
37 AROS_LIBFUNC_INIT
39 APTR newTask;
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));
55 if (newTask)
56 TaskResAddTask(TaskResBase, newTask);
58 return newTask;
60 AROS_LIBFUNC_EXIT
63 AROS_LH1(void, RemTask,
64 AROS_LHA(struct Task *, task, A1),
65 struct ExecBase *, SysBase, 48, Task)
67 AROS_LIBFUNC_INIT
69 struct Task *findTask = task;
70 struct TaskListEntry *taskEntry, *tmpEntry;
71 struct TaskResBase *TaskResBase;
72 BOOL removed = FALSE;
74 TaskResBase = (struct TaskResBase *)SysBase->lb_TaskResBase;
76 if (!findTask)
77 findTask = FindTask(NULL);
80 bug("[TaskRes] RemTask(0x%p)\n", task);
81 if (findTask != 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));
92 removed = TRUE;
93 break;
97 if (!removed)
99 #if !defined(__AROSEXEC_SMP__)
100 /* Don't let any other task interfere with us at the moment */
101 Forbid();
102 #else
103 EXEC_SPINLOCK_LOCK(&TaskResBase->TaskListSpinLock, NULL, SPINLOCK_MODE_WRITE);
104 #endif
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));
116 else
118 D(bug("[TaskRes] RemTask: flag entry for removal\n"));
119 taskEntry->tle_Task = NULL;
121 break;
124 #if !defined(__AROSEXEC_SMP__)
125 Permit();
126 #else
127 EXEC_SPINLOCK_UNLOCK(&TaskResBase->TaskListSpinLock);
128 #endif
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);
139 return;
141 AROS_LIBFUNC_EXIT