revert between 56095 -> 55830 in arch
[AROS.git] / rom / exec / findtaskbypid.c
blobcc99891fe67b5edfebda6e7003042ad9947ea264
1 /*
2 Copyright © 1995-2017, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define DEBUG 0
8 #include <exec/execbase.h>
9 #include <exec/tasks.h>
11 #include "exec_intern.h"
12 #include "exec_locks.h"
14 /*****************************************************************************
16 NAME */
17 #include <proto/exec.h>
19 AROS_LH1(struct Task *, FindTaskByPID,
21 /* SYNOPSIS */
22 AROS_LHA(ULONG, id, D0),
24 /* LOCATION */
25 struct ExecBase *, SysBase, 166, Exec)
27 /* FUNCTION
28 Scan through the task lists searching for the task whose
29 et_UniqueID field matches.
31 INPUTS
32 id - The task ID to match.
34 RESULT
35 Address of the Task control structure that matches, or
36 NULL otherwise.
38 NOTES
39 This function is source-compatible with MorphOS.
41 EXAMPLE
43 BUGS
45 SEE ALSO
47 INTERNALS
49 ******************************************************************************/
51 AROS_LIBFUNC_INIT
53 #if !defined(__AROSEXEC_SMP__)
54 struct Task *thisTask = GET_THIS_TASK;
55 #endif
56 struct Task *t;
57 struct ETask *et;
59 D(bug("[EXEC] %s()\n", __func__);)
61 /* First up, check running task(s) */
62 #if defined(__AROSEXEC_SMP__)
63 EXEC_LOCK_READ_AND_DISABLE(&PrivExecBase(SysBase)->TaskRunningSpinLock);
64 ForeachNode(&PrivExecBase(SysBase)->TaskRunning, t)
66 D(bug("[EXEC] %s: trying Running Task @ 0x%p\n", __func__, t);)
67 et = GetETask(t);
68 if (et != NULL && et->et_UniqueID == id)
70 EXEC_UNLOCK_AND_ENABLE(&PrivExecBase(SysBase)->TaskRunningSpinLock);
71 return t;
74 EXEC_UNLOCK_AND_ENABLE(&PrivExecBase(SysBase)->TaskRunningSpinLock);
76 EXEC_LOCK_READ_AND_DISABLE(&PrivExecBase(SysBase)->TaskSpinningLock);
77 ForeachNode(&PrivExecBase(SysBase)->TaskSpinning, t)
79 D(bug("[EXEC] %s: trying Spinning Task @ 0x%p\n", __func__, t);)
80 et = GetETask(t);
81 if (et != NULL && et->et_UniqueID == id)
83 EXEC_UNLOCK_AND_ENABLE(&PrivExecBase(SysBase)->TaskSpinningLock);
84 return t;
87 EXEC_UNLOCK_AND_ENABLE(&PrivExecBase(SysBase)->TaskSpinningLock);
89 EXEC_LOCK_READ_AND_DISABLE(&PrivExecBase(SysBase)->TaskReadySpinLock);
90 #else
91 Disable();
92 if ((t = thisTask) != NULL)
94 D(bug("[EXEC] %s: trying ThisTask @ 0x%p\n", __func__, t);)
95 et = GetETask(t);
96 if (et != NULL && et->et_UniqueID == id)
98 Enable();
99 return t;
102 #endif
103 /* Next, go through the ready list */
104 ForeachNode(&SysBase->TaskReady, t)
106 D(bug("[EXEC] %s: trying Ready Task @ 0x%p\n", __func__, t);)
107 et = GetETask(t);
108 if (et != NULL && et->et_UniqueID == id)
110 #if defined(__AROSEXEC_SMP__)
111 EXEC_UNLOCK_AND_ENABLE(&PrivExecBase(SysBase)->TaskReadySpinLock);
112 #else
113 Enable();
114 #endif
115 return t;
118 #if defined(__AROSEXEC_SMP__)
119 EXEC_UNLOCK_AND_ENABLE(&PrivExecBase(SysBase)->TaskReadySpinLock);
121 EXEC_LOCK_READ_AND_DISABLE(&PrivExecBase(SysBase)->TaskWaitSpinLock);
122 #endif
123 /* Finally, go through the wait list */
124 ForeachNode(&SysBase->TaskWait, t)
126 D(bug("[EXEC] %s: trying Waiting Task @ 0x%p\n", __func__, t);)
128 et = GetETask(t);
129 if (et != NULL && et->et_UniqueID == id)
131 #if defined(__AROSEXEC_SMP__)
132 EXEC_UNLOCK_AND_ENABLE(&PrivExecBase(SysBase)->TaskWaitSpinLock);
133 #else
134 Enable();
135 #endif
136 return t;
140 #if defined(__AROSEXEC_SMP__)
141 EXEC_UNLOCK_AND_ENABLE(&PrivExecBase(SysBase)->TaskWaitSpinLock);
142 #else
143 Enable();
144 #endif
146 D(bug("[EXEC] %s: Not Found\n", __func__);)
148 return NULL;
150 AROS_LIBFUNC_EXIT