OSDN Git Service

2004-07-20 Olivier Hainque <hainque@act-europe.fr>
[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 --  This package contains the tasking versions soft links.
35
36 pragma Style_Checks (All_Checks);
37 --  Turn off subprogram alpha ordering check, since we group soft link
38 --  bodies and dummy soft link bodies together separately in this unit.
39
40 pragma Polling (Off);
41 --  Turn polling off for this package. We don't need polling during any
42 --  of the routines in this package, and more to the point, if we try
43 --  to poll it can cause infinite loops.
44
45 with System.Task_Primitives.Operations;
46 --  Used for Self
47 --           Timed_Delay
48
49 package body System.Soft_Links.Tasking is
50
51    package STPO renames System.Task_Primitives.Operations;
52    package SSL  renames System.Soft_Links;
53
54    ----------------
55    -- Local Data --
56    ----------------
57
58    Initialized : Boolean := False;
59    --  Boolean flag that indicates whether the tasking soft links have
60    --  already been set.
61
62    ----------------------------------------------------------------------
63    -- Tasking versions of some services needed by non-tasking programs --
64    ----------------------------------------------------------------------
65
66    function  Get_Jmpbuf_Address return  Address;
67    procedure Set_Jmpbuf_Address (Addr : Address);
68    --  Get/Set Jmpbuf_Address for current task
69
70    function  Get_Sec_Stack_Addr return  Address;
71    procedure Set_Sec_Stack_Addr (Addr : Address);
72    --  Get/Set location of current task's secondary stack
73
74    function  Get_Machine_State_Addr return Address;
75    procedure Set_Machine_State_Addr (Addr : Address);
76    --  Get/Set the address for storing the current task's machine state
77
78    function Get_Current_Excep return SSL.EOA;
79    --  Task-safe version of SSL.Get_Current_Excep
80
81    procedure Timed_Delay_T (Time : Duration; Mode : Integer);
82    --  Task-safe version of SSL.Timed_Delay
83
84    ----------------------
85    -- Soft-Link Bodies --
86    ----------------------
87
88    function Get_Current_Excep return SSL.EOA is
89    begin
90       return STPO.Self.Common.Compiler_Data.Current_Excep'Access;
91    end Get_Current_Excep;
92
93    function Get_Jmpbuf_Address return  Address is
94    begin
95       return STPO.Self.Common.Compiler_Data.Jmpbuf_Address;
96    end Get_Jmpbuf_Address;
97
98    function Get_Machine_State_Addr return Address is
99    begin
100       return STPO.Self.Common.Compiler_Data.Machine_State_Addr;
101    end Get_Machine_State_Addr;
102
103    function Get_Sec_Stack_Addr return  Address is
104    begin
105       return STPO.Self.Common.Compiler_Data.Sec_Stack_Addr;
106    end Get_Sec_Stack_Addr;
107
108    procedure Set_Jmpbuf_Address (Addr : Address) is
109    begin
110       STPO.Self.Common.Compiler_Data.Jmpbuf_Address := Addr;
111    end Set_Jmpbuf_Address;
112
113    procedure Set_Machine_State_Addr (Addr : Address) is
114    begin
115       STPO.Self.Common.Compiler_Data.Machine_State_Addr := Addr;
116    end Set_Machine_State_Addr;
117
118    procedure Set_Sec_Stack_Addr (Addr : Address) is
119    begin
120       STPO.Self.Common.Compiler_Data.Sec_Stack_Addr := Addr;
121    end Set_Sec_Stack_Addr;
122
123    procedure Timed_Delay_T (Time : Duration; Mode : Integer) is
124    begin
125       STPO.Timed_Delay (STPO.Self, Time, Mode);
126    end Timed_Delay_T;
127
128    -----------------------------
129    -- Init_Tasking_Soft_Links --
130    -----------------------------
131
132    procedure Init_Tasking_Soft_Links is
133    begin
134       --  If the tasking soft links have already been initialized do not
135       --  repeat it.
136
137       if not Initialized then
138          --  Mark tasking soft links as initialized
139
140          Initialized := True;
141
142          --  The application being executed uses tasking so that the tasking
143          --  version of the following soft links need to be used.
144
145          SSL.Get_Jmpbuf_Address     := Get_Jmpbuf_Address'Access;
146          SSL.Set_Jmpbuf_Address     := Set_Jmpbuf_Address'Access;
147          SSL.Get_Sec_Stack_Addr     := Get_Sec_Stack_Addr'Access;
148          SSL.Set_Sec_Stack_Addr     := Set_Sec_Stack_Addr'Access;
149          SSL.Get_Machine_State_Addr := Get_Machine_State_Addr'Access;
150          SSL.Set_Machine_State_Addr := Set_Machine_State_Addr'Access;
151          SSL.Get_Current_Excep      := Get_Current_Excep'Access;
152          SSL.Timed_Delay            := Timed_Delay_T'Access;
153
154          --  No need to create a new Secondary Stack, since we will use the
155          --  default one created in s-secsta.adb
156
157          SSL.Set_Sec_Stack_Addr     (SSL.Get_Sec_Stack_Addr_NT);
158          SSL.Set_Jmpbuf_Address     (SSL.Get_Jmpbuf_Address_NT);
159          SSL.Set_Machine_State_Addr (SSL.Get_Machine_State_Addr_NT);
160       end if;
161
162    end Init_Tasking_Soft_Links;
163
164 end System.Soft_Links.Tasking;