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 --
11 -- Copyright (C) 1992-2001, Free Software Foundation, Inc. --
13 -- GNARL is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNARL; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- As a special exception, if other files instantiate generics from this --
25 -- unit, or you link this unit with other files to produce an executable, --
26 -- this unit does not by itself cause the resulting executable to be --
27 -- covered by the GNU General Public License. This exception does not --
28 -- however invalidate any other reasons why the executable file might be --
29 -- covered by the GNU Public License. --
31 -- GNARL was developed by the GNARL team at Florida State University. It is --
32 -- now maintained by Ada Core Technologies, Inc. (http://www.gnat.com). --
34 ------------------------------------------------------------------------------
36 with Ada.Task_Identification;
42 with System.Task_Primitives.Operations;
43 -- used for Write_Lock
53 -- used for Raise_Exception
55 with System.Tasking.Initialization;
56 -- used for Defer/Undefer_Abort
58 with System.Parameters;
59 -- used for Single_Lock
61 with Unchecked_Conversion;
63 package body Ada.Dynamic_Priorities is
65 package STPO renames System.Task_Primitives.Operations;
67 use System.Parameters;
71 function Convert_Ids is new
73 (Task_Identification.Task_Id, System.Tasking.Task_ID);
79 -- Inquire base priority of a task
82 (T : Ada.Task_Identification.Task_Id :=
83 Ada.Task_Identification.Current_Task)
84 return System.Any_Priority is
86 Target : constant Task_ID := Convert_Ids (T);
87 Error_Message : constant String := "Trying to get the priority of a ";
90 if Target = Convert_Ids (Ada.Task_Identification.Null_Task_Id) then
91 Raise_Exception (Program_Error'Identity,
92 Error_Message & "null task");
95 if Task_Identification.Is_Terminated (T) then
96 Raise_Exception (Tasking_Error'Identity,
97 Error_Message & "null task");
100 return Target.Common.Base_Priority;
107 -- Change base priority of a task dynamically
109 procedure Set_Priority
110 (Priority : System.Any_Priority;
111 T : Ada.Task_Identification.Task_Id :=
112 Ada.Task_Identification.Current_Task)
114 Target : constant Task_ID := Convert_Ids (T);
115 Self_ID : constant Task_ID := STPO.Self;
116 Error_Message : constant String := "Trying to set the priority of a ";
119 if Target = Convert_Ids (Ada.Task_Identification.Null_Task_Id) then
120 Raise_Exception (Program_Error'Identity,
121 Error_Message & "null task");
124 if Task_Identification.Is_Terminated (T) then
125 Raise_Exception (Tasking_Error'Identity,
126 Error_Message & "terminated task");
129 Initialization.Defer_Abort (Self_ID);
135 STPO.Write_Lock (Target);
137 if Self_ID = Target then
138 Target.Common.Base_Priority := Priority;
139 STPO.Set_Priority (Target, Priority);
141 STPO.Unlock (Target);
148 -- Yield is needed to enforce FIFO task dispatching.
149 -- LL Set_Priority is made while holding the RTS lock so that
150 -- it is inheriting high priority until it release all the RTS
152 -- If this is used in a system where Ceiling Locking is
153 -- not enforced we may end up getting two Yield effects.
156 Target.New_Base_Priority := Priority;
157 Target.Pending_Priority_Change := True;
158 Target.Pending_Action := True;
160 STPO.Wakeup (Target, Target.Common.State);
161 -- If the task is suspended, wake it up to perform the change.
162 -- check for ceiling violations ???
164 STPO.Unlock (Target);
171 Initialization.Undefer_Abort (Self_ID);
174 end Ada.Dynamic_Priorities;