2 Copyright © 1995-2017, The AROS Development Team. All rights reserved.
8 #include <exec/execbase.h>
9 #include <exec/tasks.h>
11 #include "exec_intern.h"
12 #include "exec_locks.h"
14 /*****************************************************************************
17 #include <proto/exec.h>
19 AROS_LH1(struct Task
*, FindTaskByPID
,
22 AROS_LHA(ULONG
, id
, D0
),
25 struct ExecBase
*, SysBase
, 166, Exec
)
28 Scan through the task lists searching for the task whose
29 et_UniqueID field matches.
32 id - The task ID to match.
35 Address of the Task control structure that matches, or
39 This function is source-compatible with MorphOS.
49 ******************************************************************************/
53 #if !defined(__AROSEXEC_SMP__)
54 struct Task
*thisTask
= GET_THIS_TASK
;
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
);)
68 if (et
!= NULL
&& et
->et_UniqueID
== id
)
70 EXEC_UNLOCK_AND_ENABLE(&PrivExecBase(SysBase
)->TaskRunningSpinLock
);
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
);)
81 if (et
!= NULL
&& et
->et_UniqueID
== id
)
83 EXEC_UNLOCK_AND_ENABLE(&PrivExecBase(SysBase
)->TaskSpinningLock
);
87 EXEC_UNLOCK_AND_ENABLE(&PrivExecBase(SysBase
)->TaskSpinningLock
);
89 EXEC_LOCK_READ_AND_DISABLE(&PrivExecBase(SysBase
)->TaskReadySpinLock
);
92 if ((t
= thisTask
) != NULL
)
94 D(bug("[EXEC] %s: trying ThisTask @ 0x%p\n", __func__
, t
);)
96 if (et
!= NULL
&& et
->et_UniqueID
== id
)
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
);)
108 if (et
!= NULL
&& et
->et_UniqueID
== id
)
110 #if defined(__AROSEXEC_SMP__)
111 EXEC_UNLOCK_AND_ENABLE(&PrivExecBase(SysBase
)->TaskReadySpinLock
);
118 #if defined(__AROSEXEC_SMP__)
119 EXEC_UNLOCK_AND_ENABLE(&PrivExecBase(SysBase
)->TaskReadySpinLock
);
121 EXEC_LOCK_READ_AND_DISABLE(&PrivExecBase(SysBase
)->TaskWaitSpinLock
);
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
);)
129 if (et
!= NULL
&& et
->et_UniqueID
== id
)
131 #if defined(__AROSEXEC_SMP__)
132 EXEC_UNLOCK_AND_ENABLE(&PrivExecBase(SysBase
)->TaskWaitSpinLock
);
140 #if defined(__AROSEXEC_SMP__)
141 EXEC_UNLOCK_AND_ENABLE(&PrivExecBase(SysBase
)->TaskWaitSpinLock
);
146 D(bug("[EXEC] %s: Not Found\n", __func__
);)