grub2: bring back build of aros-side grub2 tools
[AROS.git] / rom / task / NextTaskEntry.c
blobaea1926e6b15cf508d68cf0732b1a4c1deb2ab46
1 /*
2 Copyright © 2015, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define DEBUG 0
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 /*****************************************************************************
20 NAME */
21 #include <proto/task.h>
23 AROS_LH2(struct Task *, NextTaskEntry,
25 /* SYNOPSIS */
26 AROS_LHA(struct TaskList *, tlist, D1),
27 AROS_LHA(ULONG , flags, D2),
29 /* LOCATION */
30 struct TaskResBase *, TaskResBase, 3, Task)
32 /* FUNCTION
33 Looks for the next task list entry with the right type. The list
34 must be locked for this.
36 INPUTS
37 tlist - the value given by LockTaskList()
38 flags - the same flags as given to LockTaskList() or a subset
39 of them.
41 RESULT
42 Pointer to task entry found or NULL if the are no more entries.
44 NOTES
46 EXAMPLE
48 BUGS
50 SEE ALSO
51 LockTaskList(), UnLockTaskList()
53 INTERNALS
55 *****************************************************************************/
57 AROS_LIBFUNC_INIT
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));
64 if (taskList)
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);
105 return retVal;
107 AROS_LIBFUNC_EXIT
108 } /* NextTaskEntry */