graphics.library: MakeVPort() RastInfo based double-buffering fixes
[AROS.git] / rom / exec / findtask.c
blob67bdd6c79ad0c4058c1efbff255ac2432b1346a4
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>
12 /*****************************************************************************
14 NAME */
16 AROS_LH1(struct Task *, FindTask,
18 /* SYNOPSIS */
19 AROS_LHA(CONST_STRPTR, name, A1),
21 /* LOCATION */
22 struct ExecBase *, SysBase, 49, Exec)
24 /* FUNCTION
25 Find a task with a given name or get the address of the current task.
26 Finding the address of the current task is a very quick function
27 call, but finding a special task is a very CPU intensive instruction.
28 Note that generally a task may already be gone when this function
29 returns.
31 INPUTS
32 name - Pointer to name or NULL for current task.
34 RESULT
35 Address of task structure found.
37 NOTES
39 EXAMPLE
41 BUGS
43 SEE ALSO
45 INTERNALS
47 ******************************************************************************/
49 AROS_LIBFUNC_INIT
51 struct Task *ret;
53 /* Quick return for a quick argument */
54 if(name==NULL)
55 return SysBase->ThisTask;
57 /* Always protect task lists with a Disable(). */
58 Disable();
60 /* First look into the ready list. */
61 ret=(struct Task *)FindName(&SysBase->TaskReady,name);
62 if(ret==NULL)
64 /* Then into the waiting list. */
65 ret=(struct Task *)FindName(&SysBase->TaskWait,name);
66 if(ret==NULL)
69 Finally test the current task. Note that generally
70 you know the name of your own task - so it is close
71 to nonsense to look for it this way.
73 char *s1=SysBase->ThisTask->tc_Node.ln_Name;
74 const char *s2=name;
76 /* Check as long as the names are identical. */
77 while(*s1++==*s2)
78 /* Terminator found? */
79 if(!*s2++)
81 /* Got it. */
82 ret=SysBase->ThisTask;
83 break;
88 /* Return whatever I found. */
89 Enable();
90 return ret;
91 AROS_LIBFUNC_EXIT
92 } /* FindTask */