OSDN Git Service

* 41intnam.ads, 42intnam.ads, 4aintnam.ads, 4cintnam.ads,
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-taprob.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                GNU ADA RUN-TIME LIBRARY (GNARL) COMPONENTS               --
4 --                                                                          --
5 --      S Y S T E M . T A S K I N G . P R O T E C T E D _ O B J E C T S     --
6 --                                                                          --
7 --                                  B o d y                                 --
8 --                                                                          --
9 --                             $Revision$
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 ------------------------------------------------------------------------------
36
37 pragma Polling (Off);
38 --  Turn off polling, we do not want ATC polling to take place during
39 --  tasking operations. It causes infinite loops and other problems.
40
41 with System.Task_Primitives.Operations;
42 --  used for Write_Lock
43 --           Unlock
44
45 with System.Parameters;
46 --  used for Runtime_Traces
47
48 with System.Traces;
49 --  used for Send_Trace_Info
50
51 package body System.Tasking.Protected_Objects is
52
53    use System.Task_Primitives.Operations;
54    use System.Traces;
55
56    -------------------------
57    -- Finalize_Protection --
58    -------------------------
59
60    procedure Finalize_Protection (Object : in out Protection) is
61    begin
62       Finalize_Lock (Object.L'Unrestricted_Access);
63    end Finalize_Protection;
64
65    ---------------------------
66    -- Initialize_Protection --
67    ---------------------------
68
69    procedure Initialize_Protection
70      (Object           : Protection_Access;
71       Ceiling_Priority : Integer)
72    is
73       Init_Priority : Integer := Ceiling_Priority;
74    begin
75       if Init_Priority = Unspecified_Priority then
76          Init_Priority  := System.Priority'Last;
77       end if;
78
79       Initialize_Lock (Init_Priority, Object.L'Access);
80       Object.Ceiling := System.Any_Priority (Init_Priority);
81    end Initialize_Protection;
82
83    ----------
84    -- Lock --
85    ----------
86
87    procedure Lock (Object : Protection_Access) is
88       Ceiling_Violation : Boolean;
89    begin
90       --  The lock is made without defering abortion.
91
92       --  Therefore the abortion has to be deferred before calling this
93       --  routine. This means that the compiler has to generate a Defer_Abort
94       --  call before the call to Lock.
95
96       --  The caller is responsible for undeferring abortion, and compiler
97       --  generated calls must be protected with cleanup handlers to ensure
98       --  that abortion is undeferred in all cases.
99
100       Write_Lock (Object.L'Access, Ceiling_Violation);
101
102       if Parameters.Runtime_Traces then
103          Send_Trace_Info (PO_Lock);
104       end if;
105
106       if Ceiling_Violation then
107          raise Program_Error;
108       end if;
109    end Lock;
110
111    --------------------
112    -- Lock_Read_Only --
113    --------------------
114
115    procedure Lock_Read_Only (Object : Protection_Access) is
116       Ceiling_Violation : Boolean;
117    begin
118       Read_Lock (Object.L'Access, Ceiling_Violation);
119
120       if Parameters.Runtime_Traces then
121          Send_Trace_Info (PO_Lock);
122       end if;
123
124       if Ceiling_Violation then
125          raise Program_Error;
126       end if;
127    end Lock_Read_Only;
128
129    ------------
130    -- Unlock --
131    ------------
132
133    procedure Unlock (Object : Protection_Access) is
134    begin
135       Unlock (Object.L'Access);
136
137       if Parameters.Runtime_Traces then
138          Send_Trace_Info (PO_Unlock);
139       end if;
140    end Unlock;
141
142 end System.Tasking.Protected_Objects;