D.5.1 Dynamic Priorities for Tasks
This subclause describes how the base priority of
a task can be modified or queried at run time.
Static Semantics
The following language-defined
library package exists:
with System;
with Ada.Task_Identification;
-- See C.7.1
package Ada.Dynamic_Priorities
with Preelaborate, Nonblocking, Global =>
in out synchronized is
procedure Set_Priority(Priority :
in System.Any_Priority;
T :
in Ada.Task_Identification.Task_Id :=
Ada.Task_Identification.Current_Task);
function Get_Priority (T : Ada.Task_Identification.Task_Id :=
Ada.Task_Identification.Current_Task)
return System.Any_Priority;
end Ada.Dynamic_Priorities;
Dynamic Semantics
The procedure Set_Priority sets the base priority
of the specified task to the specified Priority value. Set_Priority has
no effect if the task is terminated.
The function Get_Priority returns T's current base
priority. Tasking_Error is raised if the task is terminated.
Program_Error is raised by Set_Priority and Get_Priority
if T is equal to Null_Task_Id.
On a system with a single processor, the setting
of the base priority of a task T to the new value occurs immediately
at the first point when T is outside the execution of a protected
action.
Paragraph 11 was
deleted.
Erroneous Execution
If any subprogram in this package
is called with a parameter T that specifies a task object that no longer
exists, the execution of the program is erroneous.
Documentation Requirements
On a multiprocessor, the implementation shall document
any conditions that cause the completion of the setting of the priority
of a task to be delayed later than what is specified for a single processor.
Metrics
The implementation
shall document the following metric:
The execution time of a call to Set_Priority, for
the nonpreempting case, in processor clock cycles. This is measured for
a call that modifies the priority of a ready task that is not running
(which cannot be the calling one), where the new base priority of the
affected task is lower than the active priority of the calling task,
and the affected task is not on any entry queue and is not executing
a protected operation.
NOTE 1 Setting a task's base priority
affects task dispatching. First, it can change the task's active priority.
Second, under the FIFO_Within_Priorities policy it always causes the
task to move to the tail of the ready queue corresponding to its active
priority, even if the new base priority is unchanged.
NOTE 2 Under the priority queuing
policy, setting a task's base priority has an effect on a queued entry
call if the task is blocked waiting for the call. That is, setting the
base priority of a task causes the priority of a queued entry call from
that task to be updated and the call to be removed and then reinserted
in the entry queue at the new priority (see
D.4),
unless the call originated from the
triggering_statement
of an
asynchronous_select.
NOTE 3 The effect of two or more
Set_Priority calls executed in parallel on the same task is defined as
executing these calls in some serial order.
NOTE 4 The rule for when Tasking_Error
is raised for Set_Priority or Get_Priority is different from the rule
for when Tasking_Error is raised on an entry call (see
9.5.3).
In particular, the priority of a completed or an abnormal task can be
queried so long as the task is not yet terminated, and the priority of
a task can be set in any task state (including for terminated tasks).
NOTE 5 Changing the priorities of
a set of tasks can be performed by a series of calls to Set_Priority
for each task separately. This can be done reliably within a protected
operation that has high enough ceiling priority to guarantee that the
operation completes without being preempted by any of the affected tasks.
Ada 2005 and 2012 Editions sponsored in part by Ada-Europe