* c-decl.c (duplicate_decls): Conditionalize DECL_SAVED_TREE copy.
[official-gcc.git] / gcc / ada / a-dynpri.adb
blobfd33b4f5fd2a0ecbdfe8527e893eb4ba953495cb
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNU ADA RUN-TIME LIBRARY (GNARL) COMPONENTS --
4 -- --
5 -- A D A . D Y N A M I C _ P R I O R I T I E S --
6 -- --
7 -- B o d y --
8 -- --
9 -- $Revision: 1.25 $
10 -- --
11 -- Copyright (C) 1991-2001 Florida State University --
12 -- --
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. --
23 -- --
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. --
30 -- --
31 -- GNARL was developed by the GNARL team at Florida State University. It is --
32 -- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
33 -- State University (http://www.gnat.com). --
34 -- --
35 ------------------------------------------------------------------------------
37 with Ada.Task_Identification;
38 -- used for Task_Id
39 -- Current_Task
40 -- Null_Task_Id
41 -- Is_Terminated
43 with System.Task_Primitives.Operations;
44 -- used for Write_Lock
45 -- Unlock
46 -- Set_Priority
47 -- Wakeup
48 -- Self
50 with System.Tasking;
51 -- used for Task_ID
53 with Ada.Exceptions;
54 -- used for Raise_Exception
56 with System.Tasking.Initialization;
57 -- used for Defer/Undefer_Abort
59 with Unchecked_Conversion;
61 package body Ada.Dynamic_Priorities is
63 use System.Tasking;
64 use Ada.Exceptions;
66 function Convert_Ids is new
67 Unchecked_Conversion
68 (Task_Identification.Task_Id, System.Tasking.Task_ID);
70 ------------------
71 -- Get_Priority --
72 ------------------
74 -- Inquire base priority of a task
76 function Get_Priority
77 (T : Ada.Task_Identification.Task_Id :=
78 Ada.Task_Identification.Current_Task)
79 return System.Any_Priority is
81 Target : constant Task_ID := Convert_Ids (T);
82 Error_Message : constant String := "Trying to get the priority of a ";
84 begin
85 if Target = Convert_Ids (Ada.Task_Identification.Null_Task_Id) then
86 Raise_Exception (Program_Error'Identity,
87 Error_Message & "null task");
88 end if;
90 if Task_Identification.Is_Terminated (T) then
91 Raise_Exception (Tasking_Error'Identity,
92 Error_Message & "null task");
93 end if;
95 return Target.Common.Base_Priority;
96 end Get_Priority;
98 ------------------
99 -- Set_Priority --
100 ------------------
102 -- Change base priority of a task dynamically
104 procedure Set_Priority
105 (Priority : System.Any_Priority;
106 T : Ada.Task_Identification.Task_Id :=
107 Ada.Task_Identification.Current_Task)
109 Target : constant Task_ID := Convert_Ids (T);
110 Self_ID : constant Task_ID := System.Task_Primitives.Operations.Self;
111 Error_Message : constant String := "Trying to set the priority of a ";
113 begin
114 if Target = Convert_Ids (Ada.Task_Identification.Null_Task_Id) then
115 Raise_Exception (Program_Error'Identity,
116 Error_Message & "null task");
117 end if;
119 if Task_Identification.Is_Terminated (T) then
120 Raise_Exception (Tasking_Error'Identity,
121 Error_Message & "terminated task");
122 end if;
124 System.Tasking.Initialization.Defer_Abort (Self_ID);
125 System.Task_Primitives.Operations.Write_Lock (Target);
127 if Self_ID = Target then
128 Target.Common.Base_Priority := Priority;
129 System.Task_Primitives.Operations.Set_Priority (Target, Priority);
130 System.Task_Primitives.Operations.Unlock (Target);
131 System.Task_Primitives.Operations.Yield;
132 -- Yield is needed to enforce FIFO task dispatching.
133 -- LL Set_Priority is made while holding the RTS lock so that
134 -- it is inheriting high priority until it release all the RTS
135 -- locks.
136 -- If this is used in a system where Ceiling Locking is
137 -- not enforced we may end up getting two Yield effects.
138 else
139 Target.New_Base_Priority := Priority;
140 Target.Pending_Priority_Change := True;
141 Target.Pending_Action := True;
143 System.Task_Primitives.Operations.Wakeup
144 (Target, Target.Common.State);
145 -- If the task is suspended, wake it up to perform the change.
146 -- check for ceiling violations ???
147 System.Task_Primitives.Operations.Unlock (Target);
149 end if;
150 System.Tasking.Initialization.Undefer_Abort (Self_ID);
152 end Set_Priority;
154 end Ada.Dynamic_Priorities;