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) 1991-2001 Florida State University --
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. in cooperation with Florida --
33 -- State University (http://www.gnat.com). --
35 ------------------------------------------------------------------------------
37 with Ada
.Task_Identification
;
43 with System
.Task_Primitives
.Operations
;
44 -- used for Write_Lock
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
66 function Convert_Ids
is new
68 (Task_Identification
.Task_Id
, System
.Tasking
.Task_ID
);
74 -- Inquire base priority of a task
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 ";
85 if Target
= Convert_Ids
(Ada
.Task_Identification
.Null_Task_Id
) then
86 Raise_Exception
(Program_Error
'Identity,
87 Error_Message
& "null task");
90 if Task_Identification
.Is_Terminated
(T
) then
91 Raise_Exception
(Tasking_Error
'Identity,
92 Error_Message
& "null task");
95 return Target
.Common
.Base_Priority
;
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 ";
114 if Target
= Convert_Ids
(Ada
.Task_Identification
.Null_Task_Id
) then
115 Raise_Exception
(Program_Error
'Identity,
116 Error_Message
& "null task");
119 if Task_Identification
.Is_Terminated
(T
) then
120 Raise_Exception
(Tasking_Error
'Identity,
121 Error_Message
& "terminated task");
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
136 -- If this is used in a system where Ceiling Locking is
137 -- not enforced we may end up getting two Yield effects.
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
);
150 System
.Tasking
.Initialization
.Undefer_Abort
(Self_ID
);
154 end Ada
.Dynamic_Priorities
;