OSDN Git Service

2004-07-20 Olivier Hainque <hainque@act-europe.fr>
[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 --             Copyright (C) 1991-1994, Florida State University            --
10 --             Copyright (C) 1995-2004, Ada Core Technologies               --
11 --                                                                          --
12 -- GNARL is free software; you can  redistribute it  and/or modify it under --
13 -- terms of the  GNU General Public License as published  by the Free Soft- --
14 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
15 -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
18 -- for  more details.  You should have  received  a copy of the GNU General --
19 -- Public License  distributed with GNARL; see file COPYING.  If not, write --
20 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
21 -- MA 02111-1307, USA.                                                      --
22 --                                                                          --
23 -- As a special exception,  if other files  instantiate  generics from this --
24 -- unit, or you link  this unit with other files  to produce an executable, --
25 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
26 -- covered  by the  GNU  General  Public  License.  This exception does not --
27 -- however invalidate  any other reasons why  the executable file  might be --
28 -- covered by the  GNU Public License.                                      --
29 --                                                                          --
30 -- GNARL was developed by the GNARL team at Florida State University.       --
31 -- Extensive contributions were provided by Ada Core Technologies, Inc.     --
32 --                                                                          --
33 ------------------------------------------------------------------------------
34
35 pragma Polling (Off);
36 --  Turn off polling, we do not want ATC polling to take place during
37 --  tasking operations. It causes infinite loops and other problems.
38
39 with System.Task_Primitives.Operations;
40 --  used for Write_Lock
41 --           Unlock
42
43 with System.Parameters;
44 --  used for Runtime_Traces
45
46 with System.Traces;
47 --  used for Send_Trace_Info
48
49 with System.Soft_Links.Tasking;
50 --  Used for Init_Tasking_Soft_Links
51
52 package body System.Tasking.Protected_Objects is
53
54    use System.Task_Primitives.Operations;
55    use System.Traces;
56
57    -------------------------
58    -- Finalize_Protection --
59    -------------------------
60
61    procedure Finalize_Protection (Object : in out Protection) is
62    begin
63       Finalize_Lock (Object.L'Unrestricted_Access);
64    end Finalize_Protection;
65
66    ---------------------------
67    -- Initialize_Protection --
68    ---------------------------
69
70    procedure Initialize_Protection
71      (Object           : Protection_Access;
72       Ceiling_Priority : Integer)
73    is
74       Init_Priority : Integer := Ceiling_Priority;
75    begin
76       if Init_Priority = Unspecified_Priority then
77          Init_Priority  := System.Priority'Last;
78       end if;
79
80       Initialize_Lock (Init_Priority, Object.L'Access);
81       Object.Ceiling := System.Any_Priority (Init_Priority);
82    end Initialize_Protection;
83
84    ----------
85    -- Lock --
86    ----------
87
88    procedure Lock (Object : Protection_Access) is
89       Ceiling_Violation : Boolean;
90    begin
91       --  The lock is made without defering abortion.
92
93       --  Therefore the abortion has to be deferred before calling this
94       --  routine. This means that the compiler has to generate a Defer_Abort
95       --  call before the call to Lock.
96
97       --  The caller is responsible for undeferring abortion, and compiler
98       --  generated calls must be protected with cleanup handlers to ensure
99       --  that abortion is undeferred in all cases.
100
101       Write_Lock (Object.L'Access, Ceiling_Violation);
102
103       if Parameters.Runtime_Traces then
104          Send_Trace_Info (PO_Lock);
105       end if;
106
107       if Ceiling_Violation then
108          raise Program_Error;
109       end if;
110    end Lock;
111
112    --------------------
113    -- Lock_Read_Only --
114    --------------------
115
116    procedure Lock_Read_Only (Object : Protection_Access) is
117       Ceiling_Violation : Boolean;
118    begin
119       Read_Lock (Object.L'Access, Ceiling_Violation);
120
121       if Parameters.Runtime_Traces then
122          Send_Trace_Info (PO_Lock);
123       end if;
124
125       if Ceiling_Violation then
126          raise Program_Error;
127       end if;
128    end Lock_Read_Only;
129
130    ------------
131    -- Unlock --
132    ------------
133
134    procedure Unlock (Object : Protection_Access) is
135    begin
136       Unlock (Object.L'Access);
137
138       if Parameters.Runtime_Traces then
139          Send_Trace_Info (PO_Unlock);
140       end if;
141    end Unlock;
142
143 begin
144    --  Ensure that tasking soft links are set when using protected objects
145
146    System.Soft_Links.Tasking.Init_Tasking_Soft_Links;
147 end System.Tasking.Protected_Objects;