FSF GCC merge 02/23/03
[official-gcc.git] / gcc / ada / s-taprob.adb
blobee78b57d6e36f74c1f9d134d295e8e25903bdf1b
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 -- --
10 -- Copyright (C) 1991-2001 Florida State University --
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. It is --
31 -- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
32 -- State University (http://www.gnat.com). --
33 -- --
34 ------------------------------------------------------------------------------
36 pragma Polling (Off);
37 -- Turn off polling, we do not want ATC polling to take place during
38 -- tasking operations. It causes infinite loops and other problems.
40 with System.Task_Primitives.Operations;
41 -- used for Write_Lock
42 -- Unlock
44 with System.Parameters;
45 -- used for Runtime_Traces
47 with System.Traces;
48 -- used for Send_Trace_Info
50 package body System.Tasking.Protected_Objects is
52 use System.Task_Primitives.Operations;
53 use System.Traces;
55 -------------------------
56 -- Finalize_Protection --
57 -------------------------
59 procedure Finalize_Protection (Object : in out Protection) is
60 begin
61 Finalize_Lock (Object.L'Unrestricted_Access);
62 end Finalize_Protection;
64 ---------------------------
65 -- Initialize_Protection --
66 ---------------------------
68 procedure Initialize_Protection
69 (Object : Protection_Access;
70 Ceiling_Priority : Integer)
72 Init_Priority : Integer := Ceiling_Priority;
73 begin
74 if Init_Priority = Unspecified_Priority then
75 Init_Priority := System.Priority'Last;
76 end if;
78 Initialize_Lock (Init_Priority, Object.L'Access);
79 Object.Ceiling := System.Any_Priority (Init_Priority);
80 end Initialize_Protection;
82 ----------
83 -- Lock --
84 ----------
86 procedure Lock (Object : Protection_Access) is
87 Ceiling_Violation : Boolean;
88 begin
89 -- The lock is made without defering abortion.
91 -- Therefore the abortion has to be deferred before calling this
92 -- routine. This means that the compiler has to generate a Defer_Abort
93 -- call before the call to Lock.
95 -- The caller is responsible for undeferring abortion, and compiler
96 -- generated calls must be protected with cleanup handlers to ensure
97 -- that abortion is undeferred in all cases.
99 Write_Lock (Object.L'Access, Ceiling_Violation);
101 if Parameters.Runtime_Traces then
102 Send_Trace_Info (PO_Lock);
103 end if;
105 if Ceiling_Violation then
106 raise Program_Error;
107 end if;
108 end Lock;
110 --------------------
111 -- Lock_Read_Only --
112 --------------------
114 procedure Lock_Read_Only (Object : Protection_Access) is
115 Ceiling_Violation : Boolean;
116 begin
117 Read_Lock (Object.L'Access, Ceiling_Violation);
119 if Parameters.Runtime_Traces then
120 Send_Trace_Info (PO_Lock);
121 end if;
123 if Ceiling_Violation then
124 raise Program_Error;
125 end if;
126 end Lock_Read_Only;
128 ------------
129 -- Unlock --
130 ------------
132 procedure Unlock (Object : Protection_Access) is
133 begin
134 Unlock (Object.L'Access);
136 if Parameters.Runtime_Traces then
137 Send_Trace_Info (PO_Unlock);
138 end if;
139 end Unlock;
141 end System.Tasking.Protected_Objects;