1 ------------------------------------------------------------------------------
3 -- GNU ADA RUN-TIME LIBRARY (GNARL) COMPONENTS --
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 --
10 -- Copyright (C) 1991-2001 Florida State University --
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. --
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. --
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). --
34 ------------------------------------------------------------------------------
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
44 with System
.Parameters
;
45 -- used for Runtime_Traces
48 -- used for Send_Trace_Info
50 package body System
.Tasking
.Protected_Objects
is
52 use System
.Task_Primitives
.Operations
;
55 -------------------------
56 -- Finalize_Protection --
57 -------------------------
59 procedure Finalize_Protection
(Object
: in out Protection
) is
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
;
74 if Init_Priority
= Unspecified_Priority
then
75 Init_Priority
:= System
.Priority
'Last;
78 Initialize_Lock
(Init_Priority
, Object
.L
'Access);
79 Object
.Ceiling
:= System
.Any_Priority
(Init_Priority
);
80 end Initialize_Protection
;
86 procedure Lock
(Object
: Protection_Access
) is
87 Ceiling_Violation
: Boolean;
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
);
105 if Ceiling_Violation
then
114 procedure Lock_Read_Only
(Object
: Protection_Access
) is
115 Ceiling_Violation
: Boolean;
117 Read_Lock
(Object
.L
'Access, Ceiling_Violation
);
119 if Parameters
.Runtime_Traces
then
120 Send_Trace_Info
(PO_Lock
);
123 if Ceiling_Violation
then
132 procedure Unlock
(Object
: Protection_Access
) is
134 Unlock
(Object
.L
'Access);
136 if Parameters
.Runtime_Traces
then
137 Send_Trace_Info
(PO_Unlock
);
141 end System
.Tasking
.Protected_Objects
;