2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: Change the priority of a task.
8 #include <exec/execbase.h>
9 #include <aros/libcall.h>
10 #include <proto/exec.h>
12 /*****************************************************************************
16 AROS_LH2(BYTE
, SetTaskPri
,
19 AROS_LHA(struct Task
*, task
, A1
),
20 AROS_LHA(LONG
, priority
, D0
),
23 struct ExecBase
*, SysBase
, 50, Exec
)
26 Change the priority of a given task. As a general rule the higher
27 the priority the more CPU time a task gets. Useful values are within
31 task - Pointer to task structure.
32 priority - New priority of the task.
47 ******************************************************************************/
53 /* Always Disable() when doing something with task lists. */
57 old
=task
->tc_Node
.ln_Pri
;
60 task
->tc_Node
.ln_Pri
=priority
;
62 /* Check if the task is willing to run. */
63 if(task
->tc_State
!=TS_WAIT
)
65 /* If it is in the ready list remove and reinsert it. */
66 if(task
->tc_State
==TS_READY
)
68 Remove(&task
->tc_Node
);
69 Enqueue(&SysBase
->TaskReady
,&task
->tc_Node
);
73 I could check the task priorities here to determine if
74 the following is really necessary, but OTOH priority
75 changes are rare and the hassle isn't really worth it.
77 This should be reconsidered, because of Executive [ldp].
80 /* Are taskswitches allowed? */
81 if(SysBase
->TDNestCnt
>=0||SysBase
->IDNestCnt
>0)
82 /* No. Store it for later. */
83 SysBase
->AttnResched
|=0x80;
86 /* Switches are allowed. Move the current task away. */
87 SysBase
->ThisTask
->tc_State
=TS_READY
;
88 Enqueue(&SysBase
->TaskReady
,&SysBase
->ThisTask
->tc_Node
);
90 /* And force a reschedule. */