OSDN Git Service

2004-10-04 Ed Schonberg <schonberg@gnat.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-solita.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --             S Y S T E M . S O F T _ L I N K S . T A S K I N G            --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --             Copyright (C) 2004, Free Software Foundation, Inc.           --
10 --                                                                          --
11 -- GNAT 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.  GNAT 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 GNAT;  see file COPYING.  If not, write --
19 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
20 -- MA 02111-1307, 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 -- GNAT was originally developed  by the GNAT team at  New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
31 --                                                                          --
32 ------------------------------------------------------------------------------
33
34 pragma Style_Checks (All_Checks);
35 --  Turn off subprogram alpha ordering check, since we group soft link
36 --  bodies and dummy soft link bodies together separately in this unit.
37
38 pragma Polling (Off);
39 --  Turn polling off for this package. We don't need polling during any
40 --  of the routines in this package, and more to the point, if we try
41 --  to poll it can cause infinite loops.
42
43 with System.Task_Primitives.Operations;
44 --  Used for Self
45 --           Timed_Delay
46
47 with System.Tasking;
48 --  Used for Task_Id
49
50 with Ada.Exceptions;
51 --  Used for Raise_Exception
52
53 package body System.Soft_Links.Tasking is
54
55    package STPO renames System.Task_Primitives.Operations;
56    package SSL  renames System.Soft_Links;
57
58    ----------------
59    -- Local Data --
60    ----------------
61
62    Initialized : Boolean := False;
63    --  Boolean flag that indicates whether the tasking soft links have
64    --  already been set.
65
66    -----------------------------------------------------------------
67    -- Tasking Versions of Services Needed by Non-Tasking Programs --
68    -----------------------------------------------------------------
69
70    function  Get_Jmpbuf_Address return  Address;
71    procedure Set_Jmpbuf_Address (Addr : Address);
72    --  Get/Set Jmpbuf_Address for current task
73
74    function  Get_Sec_Stack_Addr return  Address;
75    procedure Set_Sec_Stack_Addr (Addr : Address);
76    --  Get/Set location of current task's secondary stack
77
78    function  Get_Machine_State_Addr return Address;
79    procedure Set_Machine_State_Addr (Addr : Address);
80    --  Get/Set the address for storing the current task's machine state
81
82    function Get_Current_Excep return SSL.EOA;
83    --  Task-safe version of SSL.Get_Current_Excep
84
85    procedure Timed_Delay_T (Time : Duration; Mode : Integer);
86    --  Task-safe version of SSL.Timed_Delay
87
88    --------------------------
89    -- Soft-Link Get Bodies --
90    --------------------------
91
92    function Get_Current_Excep return SSL.EOA is
93    begin
94       return STPO.Self.Common.Compiler_Data.Current_Excep'Access;
95    end Get_Current_Excep;
96
97    function Get_Jmpbuf_Address return  Address is
98    begin
99       return STPO.Self.Common.Compiler_Data.Jmpbuf_Address;
100    end Get_Jmpbuf_Address;
101
102    function Get_Machine_State_Addr return Address is
103    begin
104       return STPO.Self.Common.Compiler_Data.Machine_State_Addr;
105    end Get_Machine_State_Addr;
106
107    function Get_Sec_Stack_Addr return  Address is
108    begin
109       return STPO.Self.Common.Compiler_Data.Sec_Stack_Addr;
110    end Get_Sec_Stack_Addr;
111
112    --------------------------
113    -- Soft-Link Set Bodies --
114    --------------------------
115
116    procedure Set_Jmpbuf_Address (Addr : Address) is
117    begin
118       STPO.Self.Common.Compiler_Data.Jmpbuf_Address := Addr;
119    end Set_Jmpbuf_Address;
120
121    procedure Set_Machine_State_Addr (Addr : Address) is
122    begin
123       STPO.Self.Common.Compiler_Data.Machine_State_Addr := Addr;
124    end Set_Machine_State_Addr;
125
126    procedure Set_Sec_Stack_Addr (Addr : Address) is
127    begin
128       STPO.Self.Common.Compiler_Data.Sec_Stack_Addr := Addr;
129    end Set_Sec_Stack_Addr;
130
131    -------------------
132    -- Timed_Delay_T --
133    -------------------
134
135    procedure Timed_Delay_T (Time : Duration; Mode : Integer) is
136       Self_Id : constant System.Tasking.Task_Id := STPO.Self;
137
138    begin
139       --  In case pragma Detect_Blocking is active then Program_Error
140       --  must be raised if this potentially blocking operation
141       --  is called from a protected operation.
142
143       if System.Tasking.Detect_Blocking
144         and then Self_Id.Common.Protected_Action_Nesting > 0
145       then
146          Ada.Exceptions.Raise_Exception
147            (Program_Error'Identity, "potentially blocking operation");
148       else
149          STPO.Timed_Delay (Self_Id, Time, Mode);
150       end if;
151
152    end Timed_Delay_T;
153
154    -----------------------------
155    -- Init_Tasking_Soft_Links --
156    -----------------------------
157
158    procedure Init_Tasking_Soft_Links is
159    begin
160       --  Set links only if not set already
161
162       if not Initialized then
163
164          --  Mark tasking soft links as initialized
165
166          Initialized := True;
167
168          --  The application being executed uses tasking so that the tasking
169          --  version of the following soft links need to be used.
170
171          SSL.Get_Jmpbuf_Address     := Get_Jmpbuf_Address'Access;
172          SSL.Set_Jmpbuf_Address     := Set_Jmpbuf_Address'Access;
173          SSL.Get_Sec_Stack_Addr     := Get_Sec_Stack_Addr'Access;
174          SSL.Set_Sec_Stack_Addr     := Set_Sec_Stack_Addr'Access;
175          SSL.Get_Machine_State_Addr := Get_Machine_State_Addr'Access;
176          SSL.Set_Machine_State_Addr := Set_Machine_State_Addr'Access;
177          SSL.Get_Current_Excep      := Get_Current_Excep'Access;
178          SSL.Timed_Delay            := Timed_Delay_T'Access;
179
180          --  No need to create a new Secondary Stack, since we will use the
181          --  default one created in s-secsta.adb
182
183          SSL.Set_Sec_Stack_Addr     (SSL.Get_Sec_Stack_Addr_NT);
184          SSL.Set_Jmpbuf_Address     (SSL.Get_Jmpbuf_Address_NT);
185          SSL.Set_Machine_State_Addr (SSL.Get_Machine_State_Addr_NT);
186       end if;
187    end Init_Tasking_Soft_Links;
188
189 end System.Soft_Links.Tasking;