OSDN Git Service

* doc/install.texi (xtensa-*-elf): New target.
[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 package body System.Tasking.Protected_Objects is
46
47    use System.Task_Primitives.Operations;
48
49    -------------------------
50    -- Finalize_Protection --
51    -------------------------
52
53    procedure Finalize_Protection (Object : in out Protection) is
54    begin
55       Finalize_Lock (Object.L'Unrestricted_Access);
56    end Finalize_Protection;
57
58    ---------------------------
59    -- Initialize_Protection --
60    ---------------------------
61
62    procedure Initialize_Protection
63      (Object           : Protection_Access;
64       Ceiling_Priority : Integer)
65    is
66       Init_Priority : Integer := Ceiling_Priority;
67    begin
68       if Init_Priority = Unspecified_Priority then
69          Init_Priority  := System.Priority'Last;
70       end if;
71
72       Initialize_Lock (Init_Priority, Object.L'Access);
73       Object.Ceiling := System.Any_Priority (Init_Priority);
74    end Initialize_Protection;
75
76    ----------
77    -- Lock --
78    ----------
79
80    procedure Lock (Object : Protection_Access) is
81       Ceiling_Violation : Boolean;
82    begin
83       --  The lock is made without defering abortion.
84
85       --  Therefore the abortion has to be deferred before calling this
86       --  routine. This means that the compiler has to generate a Defer_Abort
87       --  call before the call to Lock.
88
89       --  The caller is responsible for undeferring abortion, and compiler
90       --  generated calls must be protected with cleanup handlers to ensure
91       --  that abortion is undeferred in all cases.
92
93       Write_Lock (Object.L'Access, Ceiling_Violation);
94
95       if Ceiling_Violation then
96          raise Program_Error;
97       end if;
98    end Lock;
99
100    --------------------
101    -- Lock_Read_Only --
102    --------------------
103
104    procedure Lock_Read_Only (Object : Protection_Access) is
105       Ceiling_Violation : Boolean;
106    begin
107       Read_Lock (Object.L'Access, Ceiling_Violation);
108
109       if Ceiling_Violation then
110          raise Program_Error;
111       end if;
112    end Lock_Read_Only;
113
114    ------------
115    -- Unlock --
116    ------------
117
118    procedure Unlock (Object : Protection_Access) is
119    begin
120       Unlock (Object.L'Access);
121    end Unlock;
122
123 end System.Tasking.Protected_Objects;