2 Copyright © 1995-2017, The AROS Development Team. All rights reserved.
5 Desc: Search a task by name.
11 #include <exec/execbase.h>
12 #include <aros/libcall.h>
13 #include <proto/exec.h>
15 #include "exec_intern.h"
16 #include "exec_locks.h"
18 /*****************************************************************************
22 AROS_LH1(struct Task
*, FindTask
,
25 AROS_LHA(CONST_STRPTR
, name
, A1
),
28 struct ExecBase
*, SysBase
, 49, Exec
)
31 Find a task with a given name or get the address of the current task.
32 Finding the address of the current task is a very quick function
33 call, but finding a special task is a very CPU intensive instruction.
34 Note that generally a task may already be gone when this function
38 name - Pointer to name or NULL for current task.
41 Address of task structure found.
53 ******************************************************************************/
57 #if defined(__AROSEXEC_SMP__)
60 struct Task
*ret
, *thisTask
= GET_THIS_TASK
;
62 /* Quick return for a quick argument */
66 /* Always protect task lists */
67 #if defined(__AROSEXEC_SMP__)
68 EXEC_LOCK_READ_AND_DISABLE(&PrivExecBase(SysBase
)->TaskReadySpinLock
);
69 listlock
= &PrivExecBase(SysBase
)->TaskReadySpinLock
;
74 /* First look into the ready list. */
75 ret
= (struct Task
*)FindName(&SysBase
->TaskReady
, name
);
78 #if defined(__AROSEXEC_SMP__)
79 EXEC_UNLOCK_AND_ENABLE(listlock
);
80 EXEC_LOCK_READ_AND_DISABLE(&PrivExecBase(SysBase
)->TaskWaitSpinLock
);
81 listlock
= &PrivExecBase(SysBase
)->TaskWaitSpinLock
;
83 /* Then into the waiting list. */
84 ret
= (struct Task
*)FindName(&SysBase
->TaskWait
, name
);
88 Finally test the running task(s). This is mainly of importance on smp systems.
90 #if defined(__AROSEXEC_SMP__)
91 EXEC_UNLOCK_AND_ENABLE(listlock
);
92 EXEC_LOCK_READ_AND_DISABLE(&PrivExecBase(SysBase
)->TaskRunningSpinLock
);
93 listlock
= &PrivExecBase(SysBase
)->TaskRunningSpinLock
;
94 ret
= (struct Task
*)FindName(&PrivExecBase(SysBase
)->TaskRunning
, name
);
97 EXEC_UNLOCK_AND_ENABLE(listlock
);
98 EXEC_LOCK_READ_AND_DISABLE(&PrivExecBase(SysBase
)->TaskSpinningLock
);
99 listlock
= &PrivExecBase(SysBase
)->TaskSpinningLock
;
100 ret
= (struct Task
*)FindName(&PrivExecBase(SysBase
)->TaskSpinning
, name
);
105 const char *s2
= name
;
106 s1
= thisTask
->tc_Node
.ln_Name
;
107 /* Check as long as the names are identical. */
109 /* Terminator found? */
120 #if defined(__AROSEXEC_SMP__)
121 EXEC_UNLOCK_AND_ENABLE(listlock
);
126 /* Return whatever was found. */