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"
17 /*****************************************************************************
21 AROS_LH1(struct Task
*, FindTask
,
24 AROS_LHA(CONST_STRPTR
, name
, A1
),
27 struct ExecBase
*, SysBase
, 49, Exec
)
30 Find a task with a given name or get the address of the current task.
31 Finding the address of the current task is a very quick function
32 call, but finding a special task is a very CPU intensive instruction.
33 Note that generally a task may already be gone when this function
37 name - Pointer to name or NULL for current task.
40 Address of task structure found.
52 ******************************************************************************/
56 #if defined(__AROSEXEC_SMP__)
59 struct Task
*ret
, *thisTask
= GET_THIS_TASK
;
61 /* Quick return for a quick argument */
65 /* Always protect task lists */
66 #if defined(__AROSEXEC_SMP__)
67 listLock
= EXECTASK_SPINLOCK_LOCKDISABLE(&PrivExecBase(SysBase
)->TaskReadySpinLock
, SPINLOCK_MODE_READ
);
72 /* First look into the ready list. */
73 ret
= (struct Task
*)FindName(&SysBase
->TaskReady
, name
);
76 #if defined(__AROSEXEC_SMP__)
77 EXECTASK_SPINLOCK_UNLOCK(listLock
);
79 listLock
= EXECTASK_SPINLOCK_LOCKDISABLE(&PrivExecBase(SysBase
)->TaskWaitSpinLock
, SPINLOCK_MODE_READ
);
81 /* Then into the waiting list. */
82 ret
= (struct Task
*)FindName(&SysBase
->TaskWait
, name
);
86 Finally test the running task(s). This is mainly of importance on smp systems.
88 #if defined(__AROSEXEC_SMP__)
89 EXECTASK_SPINLOCK_UNLOCK(listLock
);
91 listLock
= EXECTASK_SPINLOCK_LOCKDISABLE(&PrivExecBase(SysBase
)->TaskRunningSpinLock
, SPINLOCK_MODE_READ
);
92 ret
= (struct Task
*)FindName(&PrivExecBase(SysBase
)->TaskRunning
, name
);
95 EXECTASK_SPINLOCK_UNLOCK(listLock
);
97 listLock
= EXECTASK_SPINLOCK_LOCKDISABLE(&PrivExecBase(SysBase
)->TaskSpinningLock
, SPINLOCK_MODE_READ
);
98 ret
= (struct Task
*)FindName(&PrivExecBase(SysBase
)->TaskSpinning
, name
);
103 const char *s2
= name
;
104 s1
= thisTask
->tc_Node
.ln_Name
;
105 /* Check as long as the names are identical. */
107 /* Terminator found? */
118 #if defined(__AROSEXEC_SMP__)
119 EXECTASK_SPINLOCK_UNLOCK(listLock
);
123 /* Return whatever was found. */