rename to *plain_ar for consistency. remove an erroneous space.
[AROS.git] / rom / task / NextTaskEntry.c
blobc1a1c693317da3e0b8966cc1eca014b7caf24a36
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 <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 /*****************************************************************************
20 NAME */
21 #include <proto/task.h>
23 AROS_LH2(struct Task *, NextTaskEntry,
25 /* SYNOPSIS */
26 AROS_LHA(struct TaskList *, tlist, A0),
27 AROS_LHA(ULONG , flags, D0),
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;
61 #ifdef TASKRES_ENABLE
62 ULONG matchFlags = taskList->tlp_Flags & ~LTF_WRITE;
63 ULONG matchState = 0;
65 if (flags)
66 matchFlags &= flags;
67 #endif /* TASKRES_ENABLE */
69 D(bug("[TaskRes] NextTaskEntry: tlist @ 0x%p, flags = $%lx\n", tlist, flags));
71 #ifdef TASKRES_ENABLE
72 if (taskList)
74 if (matchFlags & LTF_RUNNING)
75 matchState |= TS_RUN;
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);
96 #else
97 if (taskList)
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);
108 else
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);
130 else
131 taskList->tlp_Current = NULL;
134 retVal = taskList->tlp_Current;
136 #endif /* TASKRES_ENABLE */
138 return retVal;
140 AROS_LIBFUNC_EXIT
141 } /* NextTaskEntry */