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
)->TaskReadySpinLock
, SPINLOCK_MODE_READ
);
70 /* First look into the ready list. */
71 ret
= (struct Task
*)FindName(&SysBase
->TaskReady
, name
);
74 #if defined(__AROSEXEC_SMP__)
75 EXEC_SPINLOCK_UNLOCK(listLock
);
77 listLock
= EXEC_SPINLOCK_LOCK(&PrivExecBase(SysBase
)->TaskWaitSpinLock
, SPINLOCK_MODE_READ
);
80 /* Then into the waiting list. */
81 ret
= (struct Task
*)FindName(&SysBase
->TaskWait
, name
);
85 Finally test the running task(s). This is mainly of importance on smp systems.
87 #if defined(__AROSEXEC_SMP__)
88 listLock
= EXEC_SPINLOCK_LOCK(&PrivExecBase(SysBase
)->TaskRunningSpinLock
, SPINLOCK_MODE_READ
);
90 ret
= (struct Task
*)FindName(&PrivExecBase(SysBase
)->TaskRunning
, name
);
93 EXEC_SPINLOCK_UNLOCK(listLock
);
95 listLock
= EXEC_SPINLOCK_LOCK(&PrivExecBase(SysBase
)->TaskSpinningLock
, SPINLOCK_MODE_READ
);
97 ret
= (struct Task
*)FindName(&PrivExecBase(SysBase
)->TaskSpinning
, name
);
102 const char *s2
= name
;
103 s1
= GET_THIS_TASK
->tc_Node
.ln_Name
;
104 /* Check as long as the names are identical. */
106 /* Terminator found? */
117 #if defined(__AROSEXEC_SMP__)
118 EXEC_SPINLOCK_UNLOCK(listLock
);
124 /* Return whatever was found. */