fix build
[AROS.git] / rom / exec / settaskpri.c
blob686e5d8c7d794e37a4fe0fd5e7b9234846a93f1e
1 /*
2 Copyright © 1995-2015, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Change the priority of a task.
6 Lang: english
7 */
8 #define DEBUG 0
10 #include <aros/debug.h>
11 #include <exec/execbase.h>
12 #include <aros/libcall.h>
13 #include <proto/exec.h>
15 #include "exec_intern.h"
16 #if defined(__AROSEXEC_SMP__)
17 #include <proto/kernel.h>
18 #include "etask.h"
19 #endif
21 /*****************************************************************************
23 NAME */
25 AROS_LH2(BYTE, SetTaskPri,
27 /* SYNOPSIS */
28 AROS_LHA(struct Task *, task, A1),
29 AROS_LHA(LONG, priority, D0),
31 /* LOCATION */
32 struct ExecBase *, SysBase, 50, Exec)
34 /* FUNCTION
35 Change the priority of a given task. As a general rule the higher
36 the priority the more CPU time a task gets. Useful values are within
37 -127 to 5.
39 INPUTS
40 task - Pointer to task structure.
41 priority - New priority of the task.
43 RESULT
44 Old task priority.
46 NOTES
48 EXAMPLE
50 BUGS
52 SEE ALSO
54 INTERNALS
56 HISTORY
58 ******************************************************************************/
60 AROS_LIBFUNC_INIT
62 #if defined(__AROSEXEC_SMP__)
63 spinlock_t *task_listlock = NULL;
64 int cpunum = KrnGetCPUNumber();
65 #endif
66 BYTE old;
68 D(bug("[Exec] SetTaskPri(0x%p, %d)\n", task, priority));
70 /* Always Disable() when doing something with task lists. */
71 #if defined(__AROSEXEC_SMP__)
72 switch (task->tc_State)
74 case TS_RUN:
75 task_listlock =&PrivExecBase(SysBase)->TaskRunningSpinLock;
76 break;
77 case TS_WAIT:
78 task_listlock = &PrivExecBase(SysBase)->TaskWaitSpinLock;
79 break;
80 default:
81 task_listlock = &PrivExecBase(SysBase)->TaskReadySpinLock;
82 break;
84 EXEC_SPINLOCK_LOCK(task_listlock, (task->tc_State == TS_READY) ? SPINLOCK_MODE_WRITE : SPINLOCK_MODE_READ);
85 #endif
86 Disable();
88 /* Get returncode */
89 old = task->tc_Node.ln_Pri;
91 /* Set new value. */
92 task->tc_Node.ln_Pri = priority;
94 /* Check if the task is willing to run. */
95 if (task->tc_State != TS_WAIT)
97 /* If it is in the ready list remove and reinsert it. */
98 if (task->tc_State == TS_READY)
100 Remove(&task->tc_Node);
101 Enqueue(&SysBase->TaskReady, &task->tc_Node);
104 if (
105 #if defined(__AROSEXEC_SMP__)
106 (IntETask(task->tc_UnionETask.tc_ETask)->iet_CpuNumber == cpunum) &&
107 #endif
108 ((task->tc_State == TS_RUN) || ( task->tc_Node.ln_Pri > GET_THIS_TASK->tc_Node.ln_Pri))
111 #if defined(__AROSEXEC_SMP__)
112 EXEC_SPINLOCK_UNLOCK(task_listlock);
113 task_listlock = NULL;
114 #endif
115 Reschedule();
117 #if defined(__AROSEXEC_SMP__)
118 else
120 bug("[Exec] SetTaskPri:\n");
122 #endif
125 /* All done. */
126 #if defined(__AROSEXEC_SMP__)
127 if (task_listlock)
129 EXEC_SPINLOCK_UNLOCK(task_listlock);
131 #endif
132 Enable();
134 return old;
136 AROS_LIBFUNC_EXIT
137 } /* SetTaskPri */