2 Copyright © 1995-2015, The AROS Development Team. All rights reserved.
5 Desc: Search a task by name.
8 #include <exec/execbase.h>
9 #include <aros/libcall.h>
10 #include <proto/exec.h>
12 #include "exec_intern.h"
14 /*****************************************************************************
18 AROS_LH1(struct Task
*, FindTask
,
21 AROS_LHA(CONST_STRPTR
, name
, A1
),
24 struct ExecBase
*, SysBase
, 49, Exec
)
27 Find a task with a given name or get the address of the current task.
28 Finding the address of the current task is a very quick function
29 call, but finding a special task is a very CPU intensive instruction.
30 Note that generally a task may already be gone when this function
34 name - Pointer to name or NULL for current task.
37 Address of task structure found.
49 ******************************************************************************/
53 #if defined(__AROSEXEC_SMP__)
58 /* Quick return for a quick argument */
62 /* Always protect task lists */
63 #if defined(__AROSEXEC_SMP__)
64 listLock
= EXEC_SPINLOCK_LOCK(&PrivExecBase(SysBase
)->TaskRunningSpinLock
, SPINLOCK_MODE_READ
);
66 /* Then into the waiting list. */
67 ret
= (struct Task
*)FindName(&PrivExecBase(SysBase
)->TaskRunning
, name
);
70 EXEC_SPINLOCK_UNLOCK(listLock
);
72 listLock
= EXEC_SPINLOCK_LOCK(&PrivExecBase(SysBase
)->TaskReadySpinLock
, SPINLOCK_MODE_READ
);
78 /* First look into the ready list. */
79 ret
= (struct Task
*)FindName(&SysBase
->TaskReady
, name
);
82 #if defined(__AROSEXEC_SMP__)
83 EXEC_SPINLOCK_UNLOCK(listLock
);
85 listLock
= EXEC_SPINLOCK_LOCK(&PrivExecBase(SysBase
)->TaskWaitSpinLock
, SPINLOCK_MODE_READ
);
88 /* Then into the waiting list. */
89 ret
= (struct Task
*)FindName(&SysBase
->TaskWait
, name
);
93 Finally test the running task(s). Note that generally
94 you know the name of your own task - so it is close
95 to nonsense to look for it this way.
98 const char *s2
= name
;
100 #if defined(__AROSEXEC_SMP__)
101 EXEC_SPINLOCK_UNLOCK(listLock
);
103 listLock
= EXEC_SPINLOCK_LOCK(&PrivExecBase(SysBase
)->TaskRunningSpinLock
, SPINLOCK_MODE_READ
);
105 ForeachNode(&PrivExecBase(SysBase
)->TaskRunning
, ret
)
107 s1
= ret
->tc_Node
.ln_Name
;
109 s1
= GET_THIS_TASK
->tc_Node
.ln_Name
;
111 /* Check as long as the names are identical. */
113 /* Terminator found? */
117 #if defined(__AROSEXEC_SMP__)
123 #if defined(__AROSEXEC_SMP__)
129 #if defined(__AROSEXEC_SMP__)
131 EXEC_SPINLOCK_UNLOCK(listLock
);
137 /* Return whatever was found. */