OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [gcc/] [ada/] [a-dynpri.adb] - Blame information for rev 16

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 12 jlechner
------------------------------------------------------------------------------
2
--                                                                          --
3
--                  GNAT 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
--          Copyright (C) 1992-2005, Free Software Foundation, Inc.         --
10
--                                                                          --
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.                                              --
21
--                                                                          --
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.                                      --
28
--                                                                          --
29
-- GNARL was developed by the GNARL team at Florida State University.       --
30
-- Extensive contributions were provided by Ada Core Technologies, Inc.     --
31
--                                                                          --
32
------------------------------------------------------------------------------
33
 
34
with Ada.Task_Identification;
35
--  used for Task_Id
36
--           Current_Task
37
--           Null_Task_Id
38
--           Is_Terminated
39
 
40
with System.Task_Primitives.Operations;
41
--  used for Write_Lock
42
--           Unlock
43
--           Set_Priority
44
--           Wakeup
45
--           Self
46
 
47
with System.Tasking;
48
--  used for Task_Id
49
 
50
with System.Parameters;
51
--  used for Single_Lock
52
 
53
with System.Soft_Links;
54
--  use for Abort_Defer
55
--          Abort_Undefer
56
 
57
with Unchecked_Conversion;
58
 
59
package body Ada.Dynamic_Priorities is
60
 
61
   package STPO renames System.Task_Primitives.Operations;
62
   package SSL renames System.Soft_Links;
63
 
64
   use System.Parameters;
65
   use System.Tasking;
66
 
67
   function Convert_Ids is new
68
     Unchecked_Conversion
69
       (Task_Identification.Task_Id, System.Tasking.Task_Id);
70
 
71
   ------------------
72
   -- Get_Priority --
73
   ------------------
74
 
75
   --  Inquire base priority of a task
76
 
77
   function Get_Priority
78
     (T : Ada.Task_Identification.Task_Id :=
79
        Ada.Task_Identification.Current_Task) return System.Any_Priority
80
   is
81
      Target : constant Task_Id := Convert_Ids (T);
82
      Error_Message : constant String := "Trying to get the priority of a ";
83
 
84
   begin
85
      if Target = Convert_Ids (Ada.Task_Identification.Null_Task_Id) then
86
         raise Program_Error with Error_Message & "null task";
87
      end if;
88
 
89
      if Task_Identification.Is_Terminated (T) then
90
         raise Tasking_Error with Error_Message & "null task";
91
      end if;
92
 
93
      return Target.Common.Base_Priority;
94
   end Get_Priority;
95
 
96
   ------------------
97
   -- Set_Priority --
98
   ------------------
99
 
100
   --  Change base priority of a task dynamically
101
 
102
   procedure Set_Priority
103
     (Priority : System.Any_Priority;
104
      T        : Ada.Task_Identification.Task_Id :=
105
                   Ada.Task_Identification.Current_Task)
106
   is
107
      Target  : constant Task_Id := Convert_Ids (T);
108
      Self_ID : constant Task_Id := STPO.Self;
109
      Error_Message : constant String := "Trying to set the priority of a ";
110
 
111
   begin
112
      if Target = Convert_Ids (Ada.Task_Identification.Null_Task_Id) then
113
         raise Program_Error with Error_Message & "null task";
114
      end if;
115
 
116
      if Task_Identification.Is_Terminated (T) then
117
         raise Tasking_Error with Error_Message & "terminated task";
118
      end if;
119
 
120
      SSL.Abort_Defer.all;
121
 
122
      if Single_Lock then
123
         STPO.Lock_RTS;
124
      end if;
125
 
126
      STPO.Write_Lock (Target);
127
 
128
      if Self_ID = Target then
129
         Target.Common.Base_Priority := Priority;
130
         STPO.Set_Priority (Target, Priority);
131
 
132
         STPO.Unlock (Target);
133
 
134
         if Single_Lock then
135
            STPO.Unlock_RTS;
136
         end if;
137
 
138
         --  Yield is needed to enforce FIFO task dispatching
139
 
140
         --  LL Set_Priority is made while holding the RTS lock so that it
141
         --  is inheriting high priority until it release all the RTS locks.
142
 
143
         --  If this is used in a system where Ceiling Locking is
144
         --  not enforced we may end up getting two Yield effects.
145
 
146
         STPO.Yield;
147
 
148
      else
149
         Target.New_Base_Priority := Priority;
150
         Target.Pending_Priority_Change := True;
151
         Target.Pending_Action := True;
152
 
153
         STPO.Wakeup (Target, Target.Common.State);
154
 
155
         --  If the task is suspended, wake it up to perform the change.
156
         --  check for ceiling violations ???
157
 
158
         STPO.Unlock (Target);
159
 
160
         if Single_Lock then
161
            STPO.Unlock_RTS;
162
         end if;
163
      end if;
164
 
165
      SSL.Abort_Undefer.all;
166
   end Set_Priority;
167
 
168
end Ada.Dynamic_Priorities;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.