fix non-smp builds
[AROS.git] / rom / exec / findtask.c
blob391de35179612ca021afcc2ae7868fd581d975fe
1 /*
2 Copyright © 1995-2017, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Search a task by name.
6 Lang: english
7 */
9 #define DEBUG 0
11 #include <exec/execbase.h>
12 #include <aros/libcall.h>
13 #include <proto/exec.h>
15 #include "exec_intern.h"
16 #include "exec_locks.h"
18 /*****************************************************************************
20 NAME */
22 AROS_LH1(struct Task *, FindTask,
24 /* SYNOPSIS */
25 AROS_LHA(CONST_STRPTR, name, A1),
27 /* LOCATION */
28 struct ExecBase *, SysBase, 49, Exec)
30 /* FUNCTION
31 Find a task with a given name or get the address of the current task.
32 Finding the address of the current task is a very quick function
33 call, but finding a special task is a very CPU intensive instruction.
34 Note that generally a task may already be gone when this function
35 returns.
37 INPUTS
38 name - Pointer to name or NULL for current task.
40 RESULT
41 Address of task structure found.
43 NOTES
45 EXAMPLE
47 BUGS
49 SEE ALSO
51 INTERNALS
53 ******************************************************************************/
55 AROS_LIBFUNC_INIT
57 #if defined(__AROSEXEC_SMP__)
58 spinlock_t *listlock;
59 #endif
60 struct Task *ret, *thisTask = GET_THIS_TASK;
62 /* Quick return for a quick argument */
63 if (name == NULL)
64 return thisTask;
66 /* Always protect task lists */
67 #if defined(__AROSEXEC_SMP__)
68 EXEC_LOCK_READ_AND_DISABLE(&PrivExecBase(SysBase)->TaskReadySpinLock);
69 listlock = &PrivExecBase(SysBase)->TaskReadySpinLock;
70 #else
71 Disable();
72 #endif
74 /* First look into the ready list. */
75 ret = (struct Task *)FindName(&SysBase->TaskReady, name);
76 if (ret == NULL)
78 #if defined(__AROSEXEC_SMP__)
79 EXEC_UNLOCK_AND_ENABLE(listlock);
80 EXEC_LOCK_READ_AND_DISABLE(&PrivExecBase(SysBase)->TaskWaitSpinLock);
81 listlock = &PrivExecBase(SysBase)->TaskWaitSpinLock;
82 #endif
83 /* Then into the waiting list. */
84 ret = (struct Task *)FindName(&SysBase->TaskWait, name);
85 if (ret == NULL)
88 Finally test the running task(s). This is mainly of importance on smp systems.
90 #if defined(__AROSEXEC_SMP__)
91 EXEC_UNLOCK_AND_ENABLE(listlock);
92 EXEC_LOCK_READ_AND_DISABLE(&PrivExecBase(SysBase)->TaskRunningSpinLock);
93 listlock = &PrivExecBase(SysBase)->TaskRunningSpinLock;
94 ret = (struct Task *)FindName(&PrivExecBase(SysBase)->TaskRunning, name);
95 if (ret == NULL)
97 EXEC_UNLOCK_AND_ENABLE(listlock);
98 EXEC_LOCK_READ_AND_DISABLE(&PrivExecBase(SysBase)->TaskSpinningLock);
99 listlock = &PrivExecBase(SysBase)->TaskSpinningLock;
100 ret = (struct Task *)FindName(&PrivExecBase(SysBase)->TaskSpinning, name);
102 #else
104 char *s1;
105 const char *s2 = name;
106 s1 = thisTask->tc_Node.ln_Name;
107 /* Check as long as the names are identical. */
108 while (*s1++ == *s2)
109 /* Terminator found? */
110 if (!*s2++)
112 /* Got it. */
113 ret = thisTask;
114 break;
116 #endif
120 #if defined(__AROSEXEC_SMP__)
121 EXEC_UNLOCK_AND_ENABLE(listlock);
122 #else
123 Enable();
124 #endif
126 /* Return whatever was found. */
127 return ret;
129 AROS_LIBFUNC_EXIT
130 } /* FindTask */