2 Copyright © 1995-2015, The AROS Development Team. All rights reserved.
5 Desc: Change the priority of a task.
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>
21 /*****************************************************************************
25 AROS_LH2(BYTE
, SetTaskPri
,
28 AROS_LHA(struct Task
*, task
, A1
),
29 AROS_LHA(LONG
, priority
, D0
),
32 struct ExecBase
*, SysBase
, 50, Exec
)
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
40 task - Pointer to task structure.
41 priority - New priority of the task.
58 ******************************************************************************/
62 #if defined(__AROSEXEC_SMP__)
63 spinlock_t
*task_listlock
= NULL
;
64 int cpunum
= KrnGetCPUNumber();
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
)
75 task_listlock
=&PrivExecBase(SysBase
)->TaskRunningSpinLock
;
78 task_listlock
= &PrivExecBase(SysBase
)->TaskWaitSpinLock
;
81 task_listlock
= &PrivExecBase(SysBase
)->TaskReadySpinLock
;
84 EXEC_SPINLOCK_LOCK(task_listlock
, (task
->tc_State
== TS_READY
) ? SPINLOCK_MODE_WRITE
: SPINLOCK_MODE_READ
);
89 old
= task
->tc_Node
.ln_Pri
;
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
);
105 #if defined(__AROSEXEC_SMP__)
106 (IntETask(task
->tc_UnionETask
.tc_ETask
)->iet_CpuNumber
== cpunum
) &&
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
;
117 #if defined(__AROSEXEC_SMP__)
120 bug("[Exec] SetTaskPri:\n");
126 #if defined(__AROSEXEC_SMP__)
129 EXEC_SPINLOCK_UNLOCK(task_listlock
);