Make debug line standout more
[AROS.git] / rom / exec / findtask.c
blob5121fa1471ff95eedff71a0ec62a6be4e1414399
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Search a task by name.
6 Lang: english
7 */
8 #include <exec/execbase.h>
9 #include <aros/libcall.h>
10 #include <proto/exec.h>
11 #include "exec_intern.h"
13 /*****************************************************************************
15 NAME */
17 AROS_LH1(struct Task *, FindTask,
19 /* SYNOPSIS */
20 AROS_LHA(CONST_STRPTR, name, A1),
22 /* LOCATION */
23 struct ExecBase *, SysBase, 49, Exec)
25 /* FUNCTION
26 Find a task with a given name or get the address of the current task.
27 Finding the address of the current task is a very quick function
28 call, but finding a special task is a very CPU intensive instruction.
29 Note that generally a task may already be gone when this function
30 returns.
32 INPUTS
33 name - Pointer to name or NULL for current task.
35 RESULT
36 Address of task structure found.
38 NOTES
40 EXAMPLE
42 BUGS
44 SEE ALSO
46 INTERNALS
48 ******************************************************************************/
50 AROS_LIBFUNC_INIT
52 struct Task *ret;
54 /* Quick return for a quick argument */
55 if(name==NULL)
56 return GET_THIS_TASK;
58 /* Always protect task lists with a Disable(). */
59 Disable();
61 /* First look into the ready list. */
62 ret=(struct Task *)FindName(&SysBase->TaskReady,name);
63 if(ret==NULL)
65 /* Then into the waiting list. */
66 ret=(struct Task *)FindName(&SysBase->TaskWait,name);
67 if(ret==NULL)
70 Finally test the current task. Note that generally
71 you know the name of your own task - so it is close
72 to nonsense to look for it this way.
74 char *s1=GET_THIS_TASK->tc_Node.ln_Name;
75 const char *s2=name;
77 /* Check as long as the names are identical. */
78 while(*s1++==*s2)
79 /* Terminator found? */
80 if(!*s2++)
82 /* Got it. */
83 ret=GET_THIS_TASK;
84 break;
89 /* Return whatever I found. */
90 Enable();
91 return ret;
92 AROS_LIBFUNC_EXIT
93 } /* FindTask */