Added useful custom dimensions to some top-level drawers that lacked them.
[AROS.git] / rom / exec / findtask.c
bloba49b095c1f5a6852cbc42f0b50a67a09c632f109
1 /*
2 Copyright © 1995-2015, 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 #include "exec_intern.h"
14 /*****************************************************************************
16 NAME */
18 AROS_LH1(struct Task *, FindTask,
20 /* SYNOPSIS */
21 AROS_LHA(CONST_STRPTR, name, A1),
23 /* LOCATION */
24 struct ExecBase *, SysBase, 49, Exec)
26 /* FUNCTION
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
31 returns.
33 INPUTS
34 name - Pointer to name or NULL for current task.
36 RESULT
37 Address of task structure found.
39 NOTES
41 EXAMPLE
43 BUGS
45 SEE ALSO
47 INTERNALS
49 ******************************************************************************/
51 AROS_LIBFUNC_INIT
53 #if defined(__AROSEXEC_SMP__)
54 spinlock_t *listLock;
55 #endif
56 struct Task *ret;
58 /* Quick return for a quick argument */
59 if (name == NULL)
60 return GET_THIS_TASK;
62 /* Always protect task lists */
63 #if defined(__AROSEXEC_SMP__)
64 listLock = EXEC_SPINLOCK_LOCK(&PrivExecBase(SysBase)->TaskReadySpinLock, SPINLOCK_MODE_READ);
65 Forbid();
66 #else
67 Disable();
68 #endif
70 /* First look into the ready list. */
71 ret = (struct Task *)FindName(&SysBase->TaskReady, name);
72 if (ret == NULL)
74 #if defined(__AROSEXEC_SMP__)
75 EXEC_SPINLOCK_UNLOCK(listLock);
76 Permit();
77 listLock = EXEC_SPINLOCK_LOCK(&PrivExecBase(SysBase)->TaskWaitSpinLock, SPINLOCK_MODE_READ);
78 Forbid();
79 #endif
80 /* Then into the waiting list. */
81 ret = (struct Task *)FindName(&SysBase->TaskWait, name);
82 if (ret == NULL)
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);
89 Forbid();
90 ret = (struct Task *)FindName(&PrivExecBase(SysBase)->TaskRunning, name);
91 if (ret == NULL)
93 EXEC_SPINLOCK_UNLOCK(listLock);
94 Permit();
95 listLock = EXEC_SPINLOCK_LOCK(&PrivExecBase(SysBase)->TaskSpinningLock, SPINLOCK_MODE_READ);
96 Forbid();
97 ret = (struct Task *)FindName(&PrivExecBase(SysBase)->TaskSpinning, name);
99 #else
101 char *s1;
102 const char *s2 = name;
103 s1 = GET_THIS_TASK->tc_Node.ln_Name;
104 /* Check as long as the names are identical. */
105 while (*s1++ == *s2)
106 /* Terminator found? */
107 if (!*s2++)
109 /* Got it. */
110 ret = GET_THIS_TASK;
111 break;
113 #endif
117 #if defined(__AROSEXEC_SMP__)
118 EXEC_SPINLOCK_UNLOCK(listLock);
119 Permit();
120 #else
121 Enable();
122 #endif
124 /* Return whatever was found. */
125 return ret;
127 AROS_LIBFUNC_EXIT
128 } /* FindTask */