2 Copyright © 2015-2017, The AROS Development Team. All rights reserved.
8 #include <aros/debug.h>
9 #include <exec/types.h>
10 #include <aros/libcall.h>
11 #include <proto/utility.h>
12 #include <resources/task.h>
14 #include <resources/task.h>
16 #include "task_intern.h"
18 /*****************************************************************************
21 #include <proto/task.h>
23 AROS_LH2(struct Task
*, NextTaskEntry
,
26 AROS_LHA(struct TaskList
*, tlist
, A0
),
27 AROS_LHA(ULONG
, flags
, D0
),
30 struct TaskResBase
*, TaskResBase
, 3, Task
)
33 Looks for the next task list entry with the right type. The list
34 must be locked for this.
37 tlist - the value given by LockTaskList()
38 flags - the same flags as given to LockTaskList() or a subset
42 Pointer to task entry found or NULL if the are no more entries.
51 LockTaskList(), UnLockTaskList()
55 *****************************************************************************/
59 struct TaskListPrivate
*taskList
= (struct TaskListPrivate
*)tlist
;
60 struct Task
*retVal
= NULL
;
62 ULONG matchFlags
= taskList
->tlp_Flags
& ~LTF_WRITE
;
67 #endif /* TASKRES_ENABLE */
69 D(bug("[TaskRes] NextTaskEntry: tlist @ 0x%p, flags = $%lx\n", tlist
, flags
));
74 if (matchFlags
& LTF_RUNNING
)
77 if (matchFlags
& LTF_READY
)
78 matchState
|= (TS_READY
|TS_RUN
);
80 if (matchFlags
& LTF_WAITING
)
81 matchState
|= (TS_WAIT
|TS_SPIN
);
83 while ((taskList
->tlp_Next
) &&
84 ((!taskList
->tlp_Next
->tle_Task
) ||
85 (!(taskList
->tlp_Next
->tle_Task
->tc_State
& matchState
))))
87 taskList
->tlp_Next
= (struct TaskListEntry
*)GetSucc(taskList
->tlp_Next
);
90 if (taskList
->tlp_Next
)
92 retVal
= taskList
->tlp_Next
->tle_Task
;
93 taskList
->tlp_Next
= (struct TaskListEntry
*)GetSucc(taskList
->tlp_Next
);
99 if (!taskList
->tlp_TaskList
)
101 if (flags
& LTF_READY
)
102 taskList
->tlp_TaskList
= &SysBase
->TaskReady
;
103 else if (flags
& LTF_WAITING
)
104 taskList
->tlp_TaskList
= &SysBase
->TaskWait
;
106 return FindTask(NULL
);
110 if (!taskList
->tlp_Current
)
112 D(bug("[TaskRes] NextTaskEntry: returning first list entry...\n", tlist
, flags
));
113 if (((taskList
->tlp_Current
= (struct Task
*)GetHead(taskList
->tlp_TaskList
)) == NULL
) &&
114 ((flags
& LTF_WAITING
) && (taskList
->tlp_TaskList
== &SysBase
->TaskReady
)))
116 taskList
->tlp_TaskList
= &SysBase
->TaskWait
;
117 taskList
->tlp_Current
= (struct Task
*)GetHead(taskList
->tlp_TaskList
);
121 if (taskList
->tlp_Current
)
123 if ((retVal
= (struct Task
*)GetSucc(taskList
->tlp_Current
)) != NULL
)
124 taskList
->tlp_Current
= (struct Task
*)retVal
;
125 else if ((flags
& LTF_WAITING
) && (taskList
->tlp_TaskList
== &SysBase
->TaskReady
))
127 taskList
->tlp_TaskList
= &SysBase
->TaskWait
;
128 taskList
->tlp_Current
= (struct Task
*)GetHead(taskList
->tlp_TaskList
);
131 taskList
->tlp_Current
= NULL
;
134 retVal
= taskList
->tlp_Current
;
136 #endif /* TASKRES_ENABLE */
141 } /* NextTaskEntry */