fix comment
[AROS.git] / rom / exec / findtaskbypid.c
blob11893d73f21c00f83d67a7b300939899ba89d54b
1 /*
2 Copyright © 1995-2015, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <exec/execbase.h>
7 #include <exec/tasks.h>
9 #include "exec_intern.h"
11 /*****************************************************************************
13 NAME */
14 #include <proto/exec.h>
16 AROS_LH1(struct Task *, FindTaskByPID,
18 /* SYNOPSIS */
19 AROS_LHA(ULONG, id, D0),
21 /* LOCATION */
22 struct ExecBase *, SysBase, 166, Exec)
24 /* FUNCTION
25 Scan through the task lists searching for the task whose
26 et_UniqueID field matches.
28 INPUTS
29 id - The task ID to match.
31 RESULT
32 Address of the Task control structure that matches, or
33 NULL otherwise.
35 NOTES
36 This function is source-compatible with MorphOS.
38 EXAMPLE
40 BUGS
42 SEE ALSO
44 INTERNALS
46 ******************************************************************************/
48 AROS_LIBFUNC_INIT
50 #if defined(__AROSEXEC_SMP__)
51 spinlock_t *listLock;
52 #endif
53 struct Task *t;
54 struct ETask *et;
56 /* First up, check running task(s) */
57 #if defined(__AROSEXEC_SMP__)
58 listLock = EXEC_SPINLOCK_LOCK(&PrivExecBase(SysBase)->TaskRunningSpinLock, SPINLOCK_MODE_READ);
59 Forbid();
60 #else
61 Disable();
62 #endif
63 #if defined(__AROSEXEC_SMP__)
64 ForeachNode(&PrivExecBase(SysBase)->TaskRunning, t)
66 et = GetETask(t);
67 if (et != NULL && et->et_UniqueID == id)
69 EXEC_SPINLOCK_UNLOCK(listLock);
70 Permit();
71 return t;
74 EXEC_SPINLOCK_UNLOCK(listLock);
75 Permit();
76 listLock = EXEC_SPINLOCK_LOCK(&PrivExecBase(SysBase)->TaskReadySpinLock, SPINLOCK_MODE_READ);
77 Forbid();
78 #else
79 if (GET_THIS_TASK != NULL)
81 et = GetETask(GET_THIS_TASK);
82 if (et != NULL && et->et_UniqueID == id)
84 Enable();
85 return GET_THIS_TASK;
88 #endif
89 /* Next, go through the ready list */
90 ForeachNode(&SysBase->TaskReady, t)
92 et = GetETask(t);
93 if (et != NULL && et->et_UniqueID == id)
95 #if defined(__AROSEXEC_SMP__)
96 EXEC_SPINLOCK_UNLOCK(listLock);
97 Permit();
98 #else
99 Enable();
100 #endif
101 return t;
104 #if defined(__AROSEXEC_SMP__)
105 EXEC_SPINLOCK_UNLOCK(listLock);
106 Permit();
107 listLock = EXEC_SPINLOCK_LOCK(&PrivExecBase(SysBase)->TaskWaitSpinLock, SPINLOCK_MODE_READ);
108 Forbid();
109 #endif
110 /* Finally, go through the wait list */
111 ForeachNode(&SysBase->TaskWait, t)
113 et = GetETask(t);
114 if (et != NULL && et->et_UniqueID == id)
116 #if defined(__AROSEXEC_SMP__)
117 EXEC_SPINLOCK_UNLOCK(listLock);
118 Permit();
119 #else
120 Enable();
121 #endif
122 return t;
126 #if defined(__AROSEXEC_SMP__)
127 EXEC_SPINLOCK_UNLOCK(listLock);
128 Permit();
129 #else
130 Enable();
131 #endif
133 return NULL;
135 AROS_LIBFUNC_EXIT