2 Copyright © 2015, 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 "taskres_intern.h"
18 /*****************************************************************************
21 #include <proto/task.h>
23 AROS_LH2(struct Task
*, NextTaskEntry
,
26 AROS_LHA(struct TaskList
*, tlist
, D1
),
27 AROS_LHA(ULONG
, flags
, D2
),
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 D(bug("[TaskRes] NextTaskEntry: tlist @ 0x%p, flags = $%lx\n", tlist
, flags
));
66 if ((taskList
->tlp_Flags
& ~LTF_WRITE
) != 0)
68 if (taskList
->tlp_Flags
& LTF_RUNNING
)
70 while (taskList
->tlp_Next
&&
71 ((!taskList
->tlp_Next
->tle_Task
) ||
72 (taskList
->tlp_Next
->tle_Task
->tc_State
!= TS_RUN
)))
74 taskList
->tlp_Next
= (struct TaskListEntry
*)GetSucc(taskList
->tlp_Next
);
77 else if (taskList
->tlp_Flags
& LTF_READY
)
79 while (taskList
->tlp_Next
&&
80 ((!taskList
->tlp_Next
->tle_Task
) ||
81 (taskList
->tlp_Next
->tle_Task
->tc_State
!= TS_READY
)))
83 taskList
->tlp_Next
= (struct TaskListEntry
*)GetSucc(taskList
->tlp_Next
);
86 else if (taskList
->tlp_Flags
& LTF_WAITING
)
88 while (taskList
->tlp_Next
&&
89 ((!taskList
->tlp_Next
->tle_Task
) ||
90 !((taskList
->tlp_Next
->tle_Task
->tc_State
== TS_WAIT
) ||
91 (taskList
->tlp_Next
->tle_Task
->tc_State
== TS_SPIN
))))
93 taskList
->tlp_Next
= (struct TaskListEntry
*)GetSucc(taskList
->tlp_Next
);
98 if (taskList
->tlp_Next
)
100 retVal
= taskList
->tlp_Next
->tle_Task
;
101 taskList
->tlp_Next
= (struct TaskListEntry
*)GetSucc(taskList
->tlp_Next
);
108 } /* NextTaskEntry */