w.i.p changes for execsmp.
[AROS.git] / rom / exec / findtaskbypid.c
blob74c0d4988082e298141ac267133570ea8bab4faa
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 #endif
60 Disable();
61 #if defined(__AROSEXEC_SMP__)
62 ForeachNode(&PrivExecBase(SysBase)->TaskRunning, t)
64 et = GetETask(t);
65 if (et != NULL && et->et_UniqueID == id)
67 EXEC_SPINLOCK_UNLOCK(listLock);
68 Enable();
69 return t;
72 EXEC_SPINLOCK_UNLOCK(listLock);
73 Enable();
74 listLock = EXEC_SPINLOCK_LOCK(&PrivExecBase(SysBase)->TaskReadySpinLock, SPINLOCK_MODE_READ);
75 Disable();
76 #else
77 if (GET_THIS_TASK != NULL)
79 et = GetETask(GET_THIS_TASK);
80 if (et != NULL && et->et_UniqueID == id)
82 Enable();
83 return GET_THIS_TASK;
86 #endif
87 /* Next, go through the ready list */
88 ForeachNode(&SysBase->TaskReady, t)
90 et = GetETask(t);
91 if (et != NULL && et->et_UniqueID == id)
93 #if defined(__AROSEXEC_SMP__)
94 EXEC_SPINLOCK_UNLOCK(listLock);
95 #endif
96 Enable();
97 return t;
100 #if defined(__AROSEXEC_SMP__)
101 EXEC_SPINLOCK_UNLOCK(listLock);
102 Enable();
103 listLock = EXEC_SPINLOCK_LOCK(&PrivExecBase(SysBase)->TaskWaitSpinLock, SPINLOCK_MODE_READ);
104 Disable();
105 #endif
106 /* Finally, go through the wait list */
107 ForeachNode(&SysBase->TaskWait, t)
109 et = GetETask(t);
110 if (et != NULL && et->et_UniqueID == id)
112 #if defined(__AROSEXEC_SMP__)
113 EXEC_SPINLOCK_UNLOCK(listLock);
114 #endif
115 Enable();
116 return t;
120 #if defined(__AROSEXEC_SMP__)
121 EXEC_SPINLOCK_UNLOCK(listLock);
122 #endif
123 Enable();
125 return NULL;
127 AROS_LIBFUNC_EXIT