1 ------------------------------------------------------------------------------
3 -- GNU ADA RUN-TIME LIBRARY (GNARL) COMPONENTS --
5 -- A D A . D Y N A M I C _ P R I O R I T I E S --
10 -- Copyright (C) 1992-2001, Free Software Foundation, Inc. --
12 -- GNARL is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNARL; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
23 -- As a special exception, if other files instantiate generics from this --
24 -- unit, or you link this unit with other files to produce an executable, --
25 -- this unit does not by itself cause the resulting executable to be --
26 -- covered by the GNU General Public License. This exception does not --
27 -- however invalidate any other reasons why the executable file might be --
28 -- covered by the GNU Public License. --
30 -- GNARL was developed by the GNARL team at Florida State University. It is --
31 -- now maintained by Ada Core Technologies, Inc. (http://www.gnat.com). --
33 ------------------------------------------------------------------------------
35 with Ada.Task_Identification;
41 with System.Task_Primitives.Operations;
42 -- used for Write_Lock
52 -- used for Raise_Exception
54 with System.Tasking.Initialization;
55 -- used for Defer/Undefer_Abort
57 with System.Parameters;
58 -- used for Single_Lock
60 with Unchecked_Conversion;
62 package body Ada.Dynamic_Priorities is
64 package STPO renames System.Task_Primitives.Operations;
66 use System.Parameters;
70 function Convert_Ids is new
72 (Task_Identification.Task_Id, System.Tasking.Task_ID);
78 -- Inquire base priority of a task
81 (T : Ada.Task_Identification.Task_Id :=
82 Ada.Task_Identification.Current_Task)
83 return System.Any_Priority is
85 Target : constant Task_ID := Convert_Ids (T);
86 Error_Message : constant String := "Trying to get the priority of a ";
89 if Target = Convert_Ids (Ada.Task_Identification.Null_Task_Id) then
90 Raise_Exception (Program_Error'Identity,
91 Error_Message & "null task");
94 if Task_Identification.Is_Terminated (T) then
95 Raise_Exception (Tasking_Error'Identity,
96 Error_Message & "null task");
99 return Target.Common.Base_Priority;
106 -- Change base priority of a task dynamically
108 procedure Set_Priority
109 (Priority : System.Any_Priority;
110 T : Ada.Task_Identification.Task_Id :=
111 Ada.Task_Identification.Current_Task)
113 Target : constant Task_ID := Convert_Ids (T);
114 Self_ID : constant Task_ID := STPO.Self;
115 Error_Message : constant String := "Trying to set the priority of a ";
118 if Target = Convert_Ids (Ada.Task_Identification.Null_Task_Id) then
119 Raise_Exception (Program_Error'Identity,
120 Error_Message & "null task");
123 if Task_Identification.Is_Terminated (T) then
124 Raise_Exception (Tasking_Error'Identity,
125 Error_Message & "terminated task");
128 Initialization.Defer_Abort (Self_ID);
134 STPO.Write_Lock (Target);
136 if Self_ID = Target then
137 Target.Common.Base_Priority := Priority;
138 STPO.Set_Priority (Target, Priority);
140 STPO.Unlock (Target);
147 -- Yield is needed to enforce FIFO task dispatching.
148 -- LL Set_Priority is made while holding the RTS lock so that
149 -- it is inheriting high priority until it release all the RTS
151 -- If this is used in a system where Ceiling Locking is
152 -- not enforced we may end up getting two Yield effects.
155 Target.New_Base_Priority := Priority;
156 Target.Pending_Priority_Change := True;
157 Target.Pending_Action := True;
159 STPO.Wakeup (Target, Target.Common.State);
160 -- If the task is suspended, wake it up to perform the change.
161 -- check for ceiling violations ???
163 STPO.Unlock (Target);
170 Initialization.Undefer_Abort (Self_ID);
173 end Ada.Dynamic_Priorities;