1 ------------------------------------------------------------------------------
3 -- GNAT 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 --
9 -- Copyright (C) 1992-2006, Free Software Foundation, Inc. --
11 -- GNARL is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNARL; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
29 -- GNARL was developed by the GNARL team at Florida State University. --
30 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
32 ------------------------------------------------------------------------------
34 with System.Task_Primitives.Operations;
35 -- used for Write_Lock
44 with System.Parameters;
45 -- used for Single_Lock
47 with System.Soft_Links;
48 -- use for Abort_Defer
51 with Unchecked_Conversion;
53 package body Ada.Dynamic_Priorities is
55 package STPO renames System.Task_Primitives.Operations;
56 package SSL renames System.Soft_Links;
58 use System.Parameters;
61 function Convert_Ids is new
63 (Task_Identification.Task_Id, System.Tasking.Task_Id);
69 -- Inquire base priority of a task
72 (T : Ada.Task_Identification.Task_Id :=
73 Ada.Task_Identification.Current_Task) return System.Any_Priority
75 Target : constant Task_Id := Convert_Ids (T);
76 Error_Message : constant String := "Trying to get the priority of a ";
79 if Target = Convert_Ids (Ada.Task_Identification.Null_Task_Id) then
80 raise Program_Error with Error_Message & "null task";
83 if Task_Identification.Is_Terminated (T) then
84 raise Tasking_Error with Error_Message & "null task";
87 return Target.Common.Base_Priority;
94 -- Change base priority of a task dynamically
96 procedure Set_Priority
97 (Priority : System.Any_Priority;
98 T : Ada.Task_Identification.Task_Id :=
99 Ada.Task_Identification.Current_Task)
101 Target : constant Task_Id := Convert_Ids (T);
102 Self_ID : constant Task_Id := STPO.Self;
103 Error_Message : constant String := "Trying to set the priority of a ";
106 if Target = Convert_Ids (Ada.Task_Identification.Null_Task_Id) then
107 raise Program_Error with Error_Message & "null task";
110 if Task_Identification.Is_Terminated (T) then
111 raise Tasking_Error with Error_Message & "terminated task";
120 STPO.Write_Lock (Target);
122 if Self_ID = Target then
123 Target.Common.Base_Priority := Priority;
124 STPO.Set_Priority (Target, Priority);
126 STPO.Unlock (Target);
132 -- Yield is needed to enforce FIFO task dispatching
134 -- LL Set_Priority is made while holding the RTS lock so that it
135 -- is inheriting high priority until it release all the RTS locks.
137 -- If this is used in a system where Ceiling Locking is
138 -- not enforced we may end up getting two Yield effects.
143 Target.New_Base_Priority := Priority;
144 Target.Pending_Priority_Change := True;
145 Target.Pending_Action := True;
147 STPO.Wakeup (Target, Target.Common.State);
149 -- If the task is suspended, wake it up to perform the change.
150 -- check for ceiling violations ???
152 STPO.Unlock (Target);
159 SSL.Abort_Undefer.all;
162 end Ada.Dynamic_Priorities;