2 Copyright © 1995-2017, The AROS Development Team. All rights reserved.
5 Desc: Change the priority of a task.
10 #include <aros/debug.h>
12 #include <exec/execbase.h>
13 #include <aros/libcall.h>
14 #include <proto/exec.h>
16 #include "exec_intern.h"
17 #if defined(__AROSEXEC_SMP__)
19 #include "exec_locks.h"
22 /*****************************************************************************
26 AROS_LH2(BYTE
, SetTaskPri
,
29 AROS_LHA(struct Task
*, task
, A1
),
30 AROS_LHA(LONG
, priority
, D0
),
33 struct ExecBase
*, SysBase
, 50, Exec
)
36 Change the priority of a given task. As a general rule the higher
37 the priority the more CPU time a task gets. Useful values are within
41 task - Pointer to task structure.
42 priority - New priority of the task.
59 ******************************************************************************/
63 struct Task
*thisTask
= GET_THIS_TASK
;
64 #if defined(__AROSEXEC_SMP__)
65 spinlock_t
*task_listlock
= NULL
;
66 int cpunum
= KrnGetCPUNumber();
70 D(bug("[Exec] SetTaskPri(0x%p, %d)\n", task
, priority
);)
72 /* Always Disable() when doing something with task lists. */
73 #if defined(__AROSEXEC_SMP__)
74 switch (task
->tc_State
)
77 task_listlock
=&PrivExecBase(SysBase
)->TaskRunningSpinLock
;
80 task_listlock
= &PrivExecBase(SysBase
)->TaskWaitSpinLock
;
83 task_listlock
= &PrivExecBase(SysBase
)->TaskReadySpinLock
;
88 #if defined(__AROSEXEC_SMP__)
89 if (task
->tc_State
== TS_READY
)
90 EXEC_LOCK_WRITE(task_listlock
);
92 EXEC_LOCK_READ(task_listlock
);
96 old
= task
->tc_Node
.ln_Pri
;
99 task
->tc_Node
.ln_Pri
= priority
;
101 /* Check if the task is willing to run. */
102 if (task
->tc_State
!= TS_WAIT
)
104 /* If it is in the ready list remove and reinsert it. */
105 if (task
->tc_State
== TS_READY
)
107 Remove(&task
->tc_Node
);
108 Enqueue(&SysBase
->TaskReady
, &task
->tc_Node
);
111 #if defined(__AROSEXEC_SMP__)
112 EXEC_UNLOCK(task_listlock
);
114 task_listlock
= NULL
;
115 if (IntETask(task
->tc_UnionETask
.tc_ETask
)->iet_CpuNumber
== cpunum
) {
117 if ( task
->tc_Node
.ln_Pri
> thisTask
->tc_Node
.ln_Pri
)
119 D(bug("[Exec] SetTaskPri: Task needs reschedule...\n");)
122 #if defined(__AROSEXEC_SMP__)
124 else if (task
->tc_State
== TS_RUN
)
126 D(bug("[Exec] SetTaskPri: changing priority of task running on another cpu (%03u)\n", IntETask(task
->tc_UnionETask
.tc_ETask
)->iet_CpuNumber
);)
127 KrnScheduleCPU(IntETask(task
->tc_UnionETask
.tc_ETask
)->iet_CpuAffinity
);
133 #if defined(__AROSEXEC_SMP__)
136 EXEC_UNLOCK(task_listlock
);